• 欢迎访问奇跡の海网站,本站不上传任何资源,所有资源均来自于网络,欢迎加入奇跡の海~!奇跡の海-WordPress QQ群
  • 本站下载资源为网络上收集整理而来,并且以计算机技术研究交流为目的,版权归原作者所有,仅供大家参考,学习,不存在任何商业目的与商业用途.
  • 本站系统镜像均来自于官方原版,ed2k可视为P2P下载链接。所有操作系统默认均为试用版,如有正版密钥可以有效激活,本站不提供任何激活和相关服务。

Apache下基于名称的虚拟主机

服务器 奇跡の海 2年前 (2017-01-29) 374次浏览 已收录 0个评论 扫描二维码

To use name-based virtual hosting, you must designate the IP address (and possibly port) on the server that will be accepting requests for the hosts. This is configured using the NameVirtualHostdirective. In the normal case where any and all IP addresses on the server should be used, you can use * as the argument to NameVirtualHost. If you’re planning to use multiple ports (e.g. running SSL) you should add a Port to the argument, such as *:80. Note that mentioning an IP address in aNameVirtualHost directive does not automatically make the server listen to that IP address. SeeSetting which addresses and ports Apache uses for more details. In addition, any IP address specified here must be associated with a network interface on the server.

The next step is to create a block for each different host that you would like to serve. The argument to the directive must match a defined NameVirtualHost directive. (In this usual case, this will be “*:80”). Inside each block, you will need at minimum a ServerName directive to designate which host is served and a DocumentRoot directive to show where in the filesystem the content for that host lives.

Main host goes away

If you are adding virtual hosts to an existing web server, you must also create a block for the existing host. The ServerName and DocumentRoot included in this virtual host should be the same as the global ServerName and DocumentRoot. List this virtual host first in the configuration file so that it will act as the default host.

For example, suppose that you are serving the domain www.domain.tld and you wish to add the virtual host www.otherdomain.tld, which points at the same IP address. Then you simply add the following to httpd.conf:

NameVirtualHost *:80

ServerName www.domain.tld
ServerAlias domain.tld *.domain.tld
DocumentRoot /www/domain

ServerName www.otherdomain.tld
DocumentRoot /www/otherdomain

根据官网的示例,我在/etc/httpd/conf/httpd.conf文件末尾直接加上这几行就可以了:

apache下基于名称的虚拟主机
然后在DNS配置文件下编辑下/etc/named.conf文件,为其添加两个测试的zone:

apache下基于名称的虚拟主机

然后在/var/named目录下分别新建两个配置文件,db.test.com和db.join.com,这里为了测试只做了基于名称的DNS解析,就不做基于IP地址的DNS解析了:

apache下基于名称的虚拟主机

然后在本机的/etc/resolv.conf文件下把nameserver指定成本机就可以了,最后分别重启下DNS和HTTPD服务就行了,这里要注意的是如果selinux是开启的,记得把它关了,或者执行下chcon -u system_u -t httpd_sys_content_t -R /www这条命令,不然的话,访问会提示:

apache下基于名称的虚拟主机
出现上面的问题除了selinux的问题,还有就是/www的属主问题,记得把属组和属主都改成httpd.conf下的属:组和属主,然后给它设置权限属性:

apache下基于名称的虚拟主机

最后测试下网页:
apache下基于名称的虚拟主机

apache下基于名称的虚拟主机


版权声明:本站所有文章和资源使用CC BY-NC-SA 4.0协议授权发布 , 转载应当以相同方式注明文章来自“SeaOMC.COM->Apache下基于名称的虚拟主机!在下边可以分享本文哦!
喜欢 (0)
[]
分享 (0)
奇跡の海
关于作者:
一个WordPress菜鸟!
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址