我有一个可以运行的 Apache 2.2 服务器,但NameVirtualHost *:443 has no VirtualHosts
重新启动时会收到警告。但我做具有匹配的 VirtualHosts *:443
。
系统是Debian squeeze。ports.conf
文件如下:
NameVirtualHost *:80
Listen 80
<IfModule mod_ssl.c>
NameVirtualHost *:443
Listen 443
</IfModule>
以下是使用 apache2ctl 运行选项时的输出-S
:
% /usr/sbin/apache2ctl -S
[Sat Mar 06 10:07:11 2013] [warn] NameVirtualHost *:443 has no VirtualHosts
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:443 is a NameVirtualHost
default server q2a-dev.example.org (/etc/apache2/sites-enabled/q2a:1)
port 443 namevhost q2a-dev.example.org (/etc/apache2/sites-enabled/q2a:1)
port 443 namevhost tcert-dev.example.org (/etc/apache2/sites-enabled/tcert-dev:1)
*:80 is a NameVirtualHost
default server emailtest-dev.example.org (/etc/apache2/sites-enabled/emailtest:1)
port 80 namevhost emailtest-dev.example.org (/etc/apache2/sites-enabled/emailtest:1)
Syntax OK
两个虚拟主机在以下文件中定义/etc/apache2/sites-enabled
:
# /etc/apache2/sites-enabled/q2a
<VirtualHost *:443>
DocumentRoot /usr/share/question2answer
ServerName q2a-dev.example.org
ServerAlias q2a-dev
SSLEngine on
SSLCertificateFile /etc/ssl/certs/q2a-dev.pem
SSLCertificateKeyFile /etc/ssl/private/q2a-dev.key
DirectoryIndex index.php
</VirtualHost>
这是另一个:
# /etc/apache2/sites-enabled/tcert-dev
<VirtualHost *:443>
DocumentRoot /srv/www/tools
ServerName tcert-dev.example.org
ServerAlias tcert-dev
SSLEngine on
SSLCertificateFile /etc/ssl/certs/tcert-dev.pem
SSLCertificateKeyFile /etc/ssl/private/tcert-dev.key
<Directory "/">
AllowOverride None
</Directory>
</VirtualHost>
答案1
我找到了问题所在。在 Andrew B 建议在 pastebin 上发布更多配置后,我更仔细地查看了所有文件,发现该NameVirtualHost *:443
指令出现在两个地方:一个在目录中ports.conf
,另一个在目录中的文件中,/etc/apache2/conf.d
该目录中的所有文件都在 Apache 启动期间加载。
我删除了其中一个实例,警告就消失了。
(请注意,整个问题在 Apache 2.4 中已经消失,因为NameVirtualHost
对于出现在多个虚拟主机中的地址/端口组合而言这是隐含的。)
答案2
我也使用 Debian Squeeze,请看下面我的样子ports.conf
。
该注释来自默认文件,请注意您添加了NameVirtualHost *:443
,而我没有。
NameVirtualHost *:80
Listen 80
<IfModule mod_ssl.c>
# If you add NameVirtualHost *:443 here, you will also have to change
# the VirtualHost statement in /etc/apache2/sites-available/default-ssl
# to <VirtualHost *:443>
# Server Name Indication for SSL named virtual hosts is currently not
# supported by MSIE on Windows XP.
Listen 443
</IfModule>
<IfModule mod_gnutls.c>
Listen 443
</IfModule>
笔记:如果您希望保留NameVirtualHost *:443
,ports.conf
则应添加一个链接,以便为 443 提供默认的 VirtualHost,如下所示:
ln -s /etc/apache2/sites-available/default-ssl /etc/apache2/sites-enabled/000-default-ssl
然后我会/etc/apache2/sites-enabled/q2a
通过添加进行更新<Directory>...</Directory>
(这是您放置一些选项的地方,我通过添加一些示例来完成您的代码)。
<VirtualHost *:443>
DocumentRoot /usr/share/question2answer
ServerName q2a-dev.example.org
ServerAlias q2a-dev
SSLEngine on
SSLCertificateFile /etc/ssl/certs/q2a-dev.pem
SSLCertificateKeyFile /etc/ssl/private/q2a-dev.key
<Directory /usr/share/question2answer>
DirectoryIndex index.php
# here you can also add some other options like:
Options -Indexes FollowSymLinks MultiViews
Order deny,allow
Allow from all
AllowOverride All
</Directory>
</VirtualHost>
最后,我将/etc/apache2/sites-enabled/tcert-dev
通过更新文档根目录来进行更改<Directory>...</Directory>
。
<VirtualHost *:443>
DocumentRoot /srv/www/tools
ServerName tcert-dev.example.org
ServerAlias tcert-dev
SSLEngine on
SSLCertificateFile /etc/ssl/certs/tcert-dev.pem
SSLCertificateKeyFile /etc/ssl/private/tcert-dev.key
<Directory /srv/www/tools>
AllowOverride None
</Directory>
</VirtualHost>
我希望它有帮助。
答案3
这是一个警告,说没有为 *:443 设置虚拟主机
它看起来像
<virtualhost *:443>
</virtualhost>
如果它与 *:443 不匹配,那么它就会抛出该警告。