无法让虚拟主机工作,请看我做错了什么(CentOS 6.0)

vhost.conf,位于etc / httpd / vhost.d /

NameVirtualHost *:80 <VirtualHost *:80> ServerAdmin [email protected] ServerName localhost ServerAlias localhost.example.com DocumentRoot /var/www/html/example.com/public_html/ ErrorLog /var/www/html/example.com/logs/error.log CustomLog /var/www/html/example.com/logs/access.log combined </VirtualHost> <VirtualHost *:80> ServerAdmin [email protected] ServerName example.org ServerAlias www.example.org DocumentRoot /var/www/html/example.org/public_html/ ErrorLog /var/www/html/example.org/logs/error.log CustomLog /var/www/html/example.org/logs/access.log combined </VirtualHost> 

httpd.conf,默认设置,加到最后:

 Include /etc/httpd/vhosts.d/*.conf 

根目录:

 DocumentRoot "/var/www/html" 

上述文件夹中创build的虚拟主机的目录。 权限全部看起来是正确的。 每个public_html目录中的Index.php文件。 然而,当我冲进本地主机现在只需要我到默认的Apache 2页,我应该删除行Include /etc/httpd/vhosts.d/*.conf Web服务器工作需要从默认目录,服务任何索引文件我把那里。

基于什么types,它听起来不像你有语法错误。 所以在/ etc / hosts文件中(如果你是直接从服务器进行):

 127.0.0.1 example.org 127.0.0.1 example.com 

或者在您的PC的主机文件上:

 YOURSERVERIP example.org YOURSERVERIP example.com 

浏览到该域而不是本地主机。

你刚才看到apache网页的原因是Apache需要知道要去哪里 – 因为你还没有DNS设置,所以没有什么东西发送到Apache的主机名,所以它默认为文档的根目录。

由于Include行在VirtualHosts之后,我猜想其中包括vhost的其中之一就是重写新的。 什么“httpd -S”说? (它可能不是“httpd”,它可能是“apache2”或其他)。 -S标志将显示您configuration的所有虚拟主机,并将帮助您进行debugging。

你可以尝试删除包含行,看看是否让你的新块工作。 你也可以检查你的错误日志,看看是否有关于你的configuration文件的警告。