![首次安装 Apache2 时,如何修复 NameVirtualHost*:80 没有 VirtualHosts?](https://linux22.com/image/599517/%E9%A6%96%E6%AC%A1%E5%AE%89%E8%A3%85%20Apache2%20%E6%97%B6%EF%BC%8C%E5%A6%82%E4%BD%95%E4%BF%AE%E5%A4%8D%20NameVirtualHost*%3A80%20%E6%B2%A1%E6%9C%89%20VirtualHosts%EF%BC%9F.png)
我已经按照这里的教程创建了我的第一个服务器,并在Apache2。
当我尝试运行时/etc/init.d/apache2 restart
出现此错误:
[Mon Oct 29 11:47:17 2012] [warn] NameVirtualHost *:80 has no VirtualHosts
[Mon Oct 29 11:47:17 2012] [warn] NameVirtualHost *:80 has no VirtualHosts
这是我的/etc/apache2/conf.d/virtual.conf
#
# We're running multiple virtual hosts.
#
NameVirtualHost *:80
这是我的/etc/apache2/sites-available/www.x.com
#
# Example.com (/etc/apache2/sites-available/www.x.com)
#
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName www.x.com
ServerAlias x.com
# Indexes + Directory Root.
DirectoryIndex index.php index_screw.php index.html
DocumentRoot /home/www/www.x.com/htdocs/
# CGI Directory
ScriptAlias /cgi-bin/ /home/www/www.x.com/cgi-bin/
<Location /cgi-bin>
Options +ExecCGI
</Location>
# Logfiles
ErrorLog /home/www/www.x.com/logs/error.log
CustomLog /home/www/www.x.com/logs/access.log combined
</VirtualHost>
这是我的/etc/apache2/conf.d/httpd.conf
ServerName www.x.com
这是我的/etc/apache2/conf.d/ports.conf
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>
答案1
您要做的就是删除或评论(#)
名称虚拟主机 *:80
在 ports.conf 上
答案2
按照教程:-
“与 conf.d 目录一样,sites-enabled 目录中的每个配置文件都会在服务器启动时加载 - 而 sites-available 中的文件则会被完全忽略。
您需要在 /etc/apache2/sites-available 中创建您的主机配置文件,然后在 sites-enabled 目录中创建指向这些文件的符号链接 - 这将导致它们实际被加载/读取。”
是你做的吗?