apache多域名配置

要求:2个域名,对应1个ip,也就是一个服务器下2个目录。

跟着网上的教程找到conf.httpd

 

<VirtualHost 101.xxx.xxx.xxx:80>
    DocumentRoot /var/www/html/A
    ServerName www.A.com
   <Directory "/var/www/html/A">
        Options Indexes FollowSymLinks
        AllowOverride None
        Order allow,deny
        Allow from all
   </Directory>
</VirtualHost>


<VirtualHost 101.xxx.xxx.xxx:80>
    DocumentRoot /var/www/html/B
    ServerName www.B.com
   <Directory "/var/www/html/B">
        Options Indexes FollowSymLinks
        AllowOverride None
        Order allow,deny
        Allow from all
   </Directory>
</VirtualHost>

打开 NameVirtualHost 的注释,修改如下:
NameVirtualHost 101.xxx.xxx.xxx:80

 

然后启动httpd的时候  一直警告,
httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName
 

解决如下:
 

hostname -f 查看 hostname.
 

然后在httpd.conf最后一行添加
 

ServerName 你的hostname
 

我是这样的:
 

ServerName  localhost:80
 

重启后, 两个域名分别能访问到不同的目录下
 

或者: (未验证)
 

查看 /etc/hosts
 

显示如下:
 

127.0.0.1    localhost.localdomain localhost host.server4-245.com
 

::1          localhost.localdomain localhost host.server4-245.com
 

那么在 httpd.conf 中添加:
 

ServerName host.server4-245.com
 

参考:http://stackoverflow.com/questions/9541460/httpd-could-not-reliably-determine-the-servers-fully-qualified-domain-name-us

posted @ 2016-12-07 22:17  thewindkee  阅读(104)  评论(0编辑  收藏  举报