我想添加第二个虚拟主机到我的apacheconfiguration,但似乎无法得到新的虚拟主机使用。
我的httpd.conf只包含以下行:
ServerName radiofreebrighton.org.uk
我也有一个ports.conf文件,其中包含以下内容:
NameVirtualHost *:80 Listen 80 <IfModule mod_ssl.c> Listen 443 </IfModule>
我在sites-available有两个文件,它们是通过a2ensite sites-enabled的a2ensite链接的sites-enabled :
第一个内容是:
<VirtualHost _default_:80> DocumentRoot /home/tom/www ServerAdmin [email protected] ServerName radiofreebrighton.org.uk ServerAlias www.radiofreebrighton.org.uk <Directory /home/tom/www/> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory> ErrorLog /var/log/apache2/error.log LogLevel error CustomLog /var/log/apache2/access.log combined Alias /wiki /home/tom/www/mediawiki/index.php </VirtualHost>
后者的内容是:
<VirtualHost *:80> DocumentRoot /home/tom/tata-www ServerAdmin [email protected] ServerName trafalgararches.co.uk ServerAlias www.trafalgararches.co.uk <Directory /home/tom/tata-www/> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory> logLevel error ErrorLog /var/log/apache2/error.log </VirtualHost>
但是,无论何时我从trafalgararches.co.uk请求一个页面,我都会从radiofreebrighton.org.uk获得一个页面。 为什么会发生这种情况? 我该如何解决?
编辑:
虚拟主机configuration为apache所理解:
tom@rfb:/usr/local$ apache2ctl -S VirtualHost configuration: wildcard NameVirtualHosts and _default_ servers: *:80 is a NameVirtualHost default server radiofreebrighton.org.uk (/etc/apache2/sites-enabled/radiofreebrighton.org.uk:1) port 80 namevhost radiofreebrighton.org.uk (/etc/apache2/sites-enabled/radiofreebrighton.org.uk:1) port 80 namevhost trafalgararches.co.uk (/etc/apache2/sites-enabled/trafalgararches.co.uk:1) Syntax OK
(通过apache2ctl -S又名httpd -S )
那么这个问题已经过了一年多了,但我偶然发现了类似的“问题”。 这可能是显而易见的,但不要忘记在启用额外的虚拟主机后重新启动apache服务。 看到,执行第二个虚拟主机的apache2ctl -S , apache2ctl -S的输出将显示这两个站点都可用(其中一个是默认的),即使你没有重新加载apache。
假设你有两个虚拟主机 – site1和site2。 您运行a2ensite site1 ,然后重新加载apache服务。 现在你可以访问http://site1 ,这是默认的。 现在你运行一个2 a2ensite site2 ,但忘记重新启动apache。 apache2ctl -S的输出将是:
VirtualHost configuration: wildcard NameVirtualHosts and _default_ servers: *:80 is a NameVirtualHost default server site1 (/etc/apache2/sites-enabled/site1:1) port 80 namevhost site1 (/etc/apache2/sites-enabled/site1:1) port 80 namevhost site2 (/etc/apache2/sites-enabled/site2:1) Syntax OK
但是当你尝试加载http://site2 ,它实际上会加载默认站点(site1),因为没有加载configuration。
我有一个类似的问题,我的端口443(SSL / HTTPS)上的其他虚拟主机都被引导到列出的第一个虚拟主机的目录。 Apache本质上忽略了servername属性,只匹配ip:port。
事实certificate,我错过了命令'NameVirtualHost *:443'来为端口443启用命名虚拟主机。
'NameVirtualHost *:443'只需要被调用一次,并且必须在你的虚拟主机之上定义为端口443.我把我的定义放在ports.config文件中,所以它看起来像:
NameVirtualHost *:80 Listen 80 <IfModule mod_ssl.c> NameVirtualHost *:443 Listen 443 </IfModule> <IfModule mod_gnutls.c> NameVirtualHost *:443 Listen 443 </IfModule>
不要忘记在任何更改后重新启动Apache。
汤姆,请看这里http://httpd.apache.org/docs/2.0/en/mod/core.html#namevirtualhost
注意
请注意,“主服务器”和任何默认服务器将永远不会被用于向NameVirtualHost IP地址发送请求(除非由于某种原因您指定了NameVirtualHost,但是不为该地址定义任何VirtualHost)。
因此,如果您将默认值更改为服务器的IP地址,则应该可以。
我的2美分:因为我必须坚持一个IP(我不希望网站在所有networking上安装),事情发生在服务器本地私有IP改变之后,我忘了在这里改变它:
NameVirtualHost 192.168.100.20:80 <VirtualHost 192.168.100.20:80>
当然,让你知道IP本地不存在是不是Apache问题。
我从这里find答案: http : //alexking.org/blog/2007/11/01/apache-2-only-serves-first-virtual-host
把2个servername放在同一个VirtualHost标签中,如下所示:
<VirtualHost *:80> ServerName beta-site-1.com DocumentRoot "/Library/WebServer/beta-site-1" ServerName beta-site-2.com DocumentRoot "/Library/WebServer/beta-site-2" </VirtualHost>
我结束了第二个网站的问题,因为我有两个VirtualHost标签块。
我有这个问题迁移到一个新的Ubuntu 16服务器的网站。 在经过了一番头痛之后,我意识到SSL模块并未默认启用,所以<IfModule mod_ssl.c>块中的任何内容当然都会被忽略。
几年前,我用这个条件包装了所有的SSL虚拟主机,这次我把configuration文件复制到新的服务器上。
我通过启用模块来修复它:
sudo a2enmod ssl