Apache VirtualHost 设置…502 Bad Gateway

Apache VirtualHost 设置…502 Bad Gateway

我正在尝试在 Ubuntu 12.04 lts 上设置 apache 虚拟主机。我按照此处的指南进行操作http://www.debian-administration.org/articles/412除了我使用的是 /var/www 而不是 /home/www。我已将文档根文件夹设置为 755 权限。这是我在家里运行的服务器,所以我认为可能是我的路由器出了问题?我没有使用代理。是否需要以某种方式设置端口转发才能运行虚拟主机?(是的,在虚拟主机之前它运行良好。我收到 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 中唯一接触过的东西是我在 sites-available 中创建的新站点,然后通过 a2ensite 符号链接到 sites-enabled(随后重新加载 apache),然后在 conf.d 中创建 virtual.conf,其中包含以下内容:

#
#  We're running multiple virtual hosts.
#
  NameVirtualHost *

这是我的错误日志

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

答案1

我有几点建议:

检查路由器两侧的行为是否存在差异。假设您的服务器的内部 IP 是 192.168.0.10。编辑测试机器上的 hosts 文件(Mac 上的 /etc/hosts 和 Windows 上的 c:\windows\system32\driver\etc\hosts - 记得在 Mac 上使用 sudo 或在 Windows 上“以管理员身份运行”,否则您将无法编辑文件)并向其中添加以下行(将 192.168.0.10 替换为您的实际 IP)内部/家庭网络服务器IP):

192.168.0.10    www.labelleviemodesto.com labelleviemodesto.com
192.168.0.10    www.functioncreate.com functioncreate.com

对所有这些域名执行 ping 操作,以确保您访问的是正确的 IP。nslookup 不起作用,因为它只会查询 DNS,这将为您提供服务器的正确(外部)IP 并忽略主机文件覆盖。Ping 和所有其他程序都将遵守主机文件覆盖。显然,您需要在私人(家庭)网络内部执行此操作,例如在 Wi-Fi 上。如果 ping 针对所有 4 个域的内部 IP(192.168.0.10)(这很重要,因为例如 functioncreate.com 可能会重定向到 www.functioncreate.com 反之亦然,因此您要确保无论如何,您都在直接与内部 IP 通信,中间没有路由器)。

无论如何,最重要的是:看看您是否仍然收到 502 错误。如果收到,那么它很可能来自 Apache,并且您的配置文件有问题。如果它通过私有 IP 正常工作,但当您从外部通过路由器访问此服务器时收到 502 错误,那么问题就出在您的路由器配置上。

我的猜测是:是路由器。您的 Apache 配置中似乎没有任何类似反向代理的东西。

最后说明:确保您只有一个名称虚拟主机在所有 .conf 文件中都添加一行。如果你有多个,或者你的虚拟主机参数与您的不完全对应名称虚拟主机参数,您将得到奇怪的、意想不到的结果。例如,由于您已经定义了所有虚拟主机,如下所示:

VirtualHost *:80

确保所有 Apache 配置文件中唯一的 NameVirtualHost 行如下所示:

NameVirtualHost *:80

您不应该在日志中看到这样的行!

[Wed Feb 12 23:46:06 2014] [warn] NameVirtualHost *:80 has no VirtualHosts

当然,这不是一个直接的答案,但我希望它能让你更接近答案。:)

相关内容