我正在尝试在Ubuntu 12.04上设置apache虚拟主机。 除了我使用/ var / www不是/ home / www之外,我在这里http://www.debian-administration.org/articles/412中遵循了这个指南。 我已将文档根文件夹设置为755权限。 这是一个服务器,我用尽了我的房子,所以它可能是我的路由器可能是一个问题,我想? 我没有使用代理服务器。是否需要设置端口转发的某种方式来运行虚拟主机? (是的,它在vhosts之前工作正常,我得到了502响应错误(坏的网关),这里是我的两个启用的网站
NameVirtualHost *:80 <VirtualHost *:80> ServerName www.functioncreate.com ServerAlias functioncreate.com # Indexes + Directory Root. DirectoryIndex index.html DocumentRoot /var/www/functioncreate/htdocs/ # CGI Directory ScriptAlias /cgi-bin/ /var/www/functioncreate/cgi-bin/ <Location /cgi-bin> Options +ExecCGI </Location> # Logfiles ErrorLog /var/www/fucntioncreate/logs/error.log CustomLog /var/www/functioncreate/logs/access.log combined </VirtualHost>
第二个:
# # Example.com (/etc/apache2/sites-available/www.example.com) # <VirtualHost *:80> ServerName www.labelleviemodesto.com ServerAlias labelleviemodesto.com # Indexes + Directory Root. DirectoryIndex index.html DocumentRoot /var/www/labellevie/htdocs/ # CGI Directory ScriptAlias /cgi-bin/ /var/www/labellevie/cgi-bin/ <Location /cgi-bin> Options +ExecCGI </Location> # Logfiles ErrorLog /var/www/labellevie/logs/error.log CustomLog /var/www/labellevie/logs/access.log combined </VirtualHost>
我的httpd.conf没有任何内容。 我曾尝试启用和禁用“默认”网站。 我碰到的apache中唯一的东西就是我在site中创build的新站点,然后通过a2ensite启动,然后通过Apache重新加载,然后在conf.d中创buildvirtual.conf。
# # We're running multiple virtual hosts. # NameVirtualHost *
这是我的error.log
Warning: DocumentRoot [/var/www/functioncreate] does not exist Warning: DocumentRoot [/var/www/labellevie] does not exist apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName [Wed Feb 12 23:40:40 2014] [warn] NameVirtualHost *:80 has no VirtualHosts [Wed Feb 12 23:40:40 2014] [notice] Apache/2.2.22 (Ubuntu) PHP/5.3.10-1ubuntu3.9 with Suhosin-Patch configured -- resuming normal operations [Wed Feb 12 23:44:55 2014] [notice] Graceful restart requested, doing restart Warning: DocumentRoot [/var/www/functioncreate] does not exist Warning: DocumentRoot [/var/www/labellevie] does not exist apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName [Wed Feb 12 23:44:55 2014] [warn] NameVirtualHost *:80 has no VirtualHosts [Wed Feb 12 23:44:55 2014] [notice] Apache/2.2.22 (Ubuntu) PHP/5.3.10-1ubuntu3.9 with Suhosin-Patch configured -- resuming normal operations [Wed Feb 12 23:46:06 2014] [notice] Graceful restart requested, doing restart Warning: DocumentRoot [/var/www/labellevie] does not exist apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName [Wed Feb 12 23:46:06 2014] [warn] NameVirtualHost *:80 has no VirtualHosts [Wed Feb 12 23:46:06 2014] [notice] Apache/2.2.22 (Ubuntu) PHP/5.3.10-1ubuntu3.9 with Suhosin-Patch configured -- resuming normal operations [Wed Feb 12 23:46:29 2014] [error] [client 10.0.0.14] File does not exist: /var/www/functionCreate/favicon.ico [Thu Feb 13 00:22:45 2014] [notice] Graceful restart requested, doing restart Warning: DocumentRoot [/var/www/labellevie] does not exist apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName [Thu Feb 13 00:22:45 2014] [warn] _default_ VirtualHost overlap on port 80, the first has precedence [Thu Feb 13 00:22:45 2014] [warn] _default_ VirtualHost overlap on port 80, the first has precedence [Thu Feb 13 00:22:45 2014] [warn] NameVirtualHost *:80 has no VirtualHosts [Thu Feb 13 00:22:45 2014] [warn] NameVirtualHost *:80 has no VirtualHosts (2)No such file or directory: apache2: could not open error log file /var/www/fucntionCreate/logs/error.log. Unable to open logs [Thu Feb 13 12:03:37 2014] [warn] pid file /var/run/apache2.pid overwritten -- Unclean shutdown of previous Apache run? [Thu Feb 13 12:03:37 2014] [notice] Apache/2.2.22 (Ubuntu) PHP/5.3.10-1ubuntu3.9 with Suhosin-Patch configured -- resuming normal operations [Thu Feb 13 12:03:57 2014] [notice] caught SIGTERM, shutting down [Thu Feb 13 12:03:58 2014] [notice] Apache/2.2.22 (Ubuntu) PHP/5.3.10-1ubuntu3.9 with Suhosin-Patch configured -- resuming normal operations [Thu Feb 13 12:04:23 2014] [error] [client 166.137.191.15] File does not exist: /var/www/favicon.ico [Thu Feb 13 12:04:57 2014] [error] [client 166.137.191.15] File does not exist: /var/www/favicon.ico [Thu Feb 13 12:05:40 2014] [error] [client 186.251.208.20] script not found or unable to stat: /usr/lib/cgi-bin/php [Thu Feb 13 12:05:40 2014] [error] [client 186.251.208.20] script not found or unable to stat: /usr/lib/cgi-bin/php5 [Thu Feb 13 12:05:40 2014] [error] [client 186.251.208.20] script not found or unable to stat: /usr/lib/cgi-bin/php-cgi [Thu Feb 13 12:05:40 2014] [error] [client 186.251.208.20] script not found or unable to stat: /usr/lib/cgi-bin/php5 [Thu Feb 13 12:05:40 2014] [error] [client 186.251.208.20] script not found or unable to stat: /usr/lib/cgi-bin/php-cgi [Thu Feb 13 12:05:41 2014] [error] [client 186.251.208.20] script not found or unable to stat: /usr/lib/cgi-bin/php.cgi [Thu Feb 13 12:05:41 2014] [error] [client 186.251.208.20] script not found or unable to stat: /usr/lib/cgi-bin/php4 [Thu Feb 13 12:09:18 2014] [notice] Graceful restart requested, doing restart apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName [Thu Feb 13 12:09:19 2014] [warn] NameVirtualHost *:80 has no VirtualHosts (2)No such file or directory: apache2: could not open error log file /var/www/fucntionCreate/logs/error.log. Unable to open logs
我有一些提示:
检查路由器两侧是否有不同的行为。 假设你的服务器的内部IP是192.168.0.10。 在你的testing机器上编辑主机文件(Mac上的/ etc / hosts和Windows上的c:\ windows \ system32 \ driver \ etc \ hosts – 记住在Mac上使用sudo或者在Windows上以“admin”身份运行,否则,无法编辑文件),并添加以下行(用实际的内部/家庭networking服务器IPreplace192.168.0.10):
192.168.0.10 www.labelleviemodesto.com labelleviemodesto.com 192.168.0.10 www.functioncreate.com functioncreate.com
对所有这些域名进行平安,以确保您正确点击了正确的IP。 NSLOOKUP将无法正常工作,因为它只会查询DNS,这将为您提供服务器的适当(外部)IP,并忽略主机文件覆盖。 Ping等所有其他程序,都会尊重主机文件覆盖。 很明显,你需要在你的私人(家庭)networking里面这样做,比如在Wi-Fi上。 如果ping的目标是所有4个域的内部IP(192.168.0.10)(这很重要,例如,因为functioncreate.com可能会redirect到www.functioncreate.com,反之亦然,所以您要确保无论什么,你直接与内部IP通话,没有中间的路由器)。
无论如何,底线:看看你是否仍然得到502错误。 如果你这样做,那么它很可能来自Apache,并且你的configuration文件有问题。 如果通过私有IP可以正常工作,但是当从外部访问并通过路由器访问此服务器时,将出现502错误,则问题出在您的路由器configuration上。
我的猜测是这是路由器。 你的Apacheconfiguration中似乎没有任何类似反向代理的东西。
最后的注意事项:确保所有.conf文件中只有一个NameVirtualHost行。 如果您有多个参数,或者如果您的VirtualHost参数与您的NameVirtualHost参数不完全一致,则会出现奇怪的意外结果。 例如,由于您已经将所有虚拟主机定义为如此:
VirtualHost *:80
确保所有Apacheconfiguration文件中唯一的NameVirtualHost行如下所示:
NameVirtualHost *:80
你不应该在日志中看到这样的线条!
[Wed Feb 12 23:46:06 2014] [warn] NameVirtualHost *:80 has no VirtualHosts
当然,这不是一个直接的答案,但是我希望这会让你更接近答案。 🙂