Tom*_*ght 31 virtualhost apache-2.2
我正在尝试将第二个虚拟主机添加到我的 apache 配置中,但似乎无法使用新的虚拟主机。
我的httpd.conf只是包含以下行:
ServerName radiofreebrighton.org.uk
Run Code Online (Sandbox Code Playgroud)
我还有一个ports.conf文件,其中包含以下内容:
NameVirtualHost *:80
Listen 80
<IfModule mod_ssl.c>
Listen 443
</IfModule>
Run Code Online (Sandbox Code Playgroud)
我有两个文件,sites-available这是符号链接到sites-enabled由a2ensite:
第一段的内容是:
<VirtualHost _default_:80>
DocumentRoot /home/tom/www
ServerAdmin tom@radiofreebrighton.org.uk
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>
Run Code Online (Sandbox Code Playgroud)
后者的内容是:
<VirtualHost *:80>
DocumentRoot /home/tom/tata-www
ServerAdmin admin@trafalgararches.co.uk
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>
Run Code Online (Sandbox Code Playgroud)
但是,每当我从 trafalgararches.co.uk 请求页面时,都会收到来自 radiofreebrighton.org.uk 的页面。为什么会发生这种情况?我该如何解决?
编辑:
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
Run Code Online (Sandbox Code Playgroud)
(通过apache2ctl -Saka收集httpd -S。)
小智 18
这可能很明显,但不要忘记在启用额外的虚拟主机后重新启动 apache 服务。
a2ensite为第二个虚拟主机执行后,输出apache2ctl -S反映两个站点都已配置(其中一个是默认站点),但在您重新加载 apache 之前它不会生效。
假设您有两个虚拟主机 - site1 和 site2。您运行a2ensite site1然后重新加载 apache 服务。现在您可以访问了http://site1,这是默认设置。现在您运行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
Run Code Online (Sandbox Code Playgroud)
但是当您尝试加载时http://site2,它实际上会加载默认站点 (site1),因为未加载配置。
小智 16
我有一个类似的问题,我在端口 443 (SSL/HTTPS) 上的其他虚拟主机都被定向到列出的第一个虚拟主机的目录。Apache 基本上忽略了 servername 属性,只匹配 ip:port。
结果发现我缺少命令“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>
Run Code Online (Sandbox Code Playgroud)
不要忘记在任何更改后重新启动 apache。
| 归档时间: |
|
| 查看次数: |
79785 次 |
| 最近记录: |