NginX 作为反向代理绑定问题

NginX 作为反向代理绑定问题

我在 MediaTemple 上安装了全新的 Ubuntu 11,并将 NginX 设置为反向代理。因此,静态项目由 NginX 处理,其余项目由 apache 处理,具体说明如下:

http://wiki.mediatemple.net/w/(ve):使用 Nginx 作为反向 Web 代理

一切都很顺利,除了我执行了最后一步,即重新启动 apache,然后重新启动 NginX。Apache 重新启动正常,但当我重新启动 NginX 时,它给出了有关绑定的错误。我重新启动了服务器,然后尝试重新启动 apache,然后再次重新启动 NginX。这次 apache 报告了一个错误,但 NginX 重新启动正常。

* Restarting web server apache2                                                     
(98)Address already in use: make_sock: could not bind to address 127.0.0.1:80
no listening sockets available, shutting down
Unable to open logs
Action 'start' failed.
The Apache error log may have more information.

Apache 日志中的最新错误似乎是:

[Mon Nov 14 06:47:13 2011] [notice] caught SIGTERM, shutting down
[Mon Nov 14 06:47:14 2011] [notice] Apache/2.2.17 (Ubuntu) configured -- resuming normal operations
[Mon Nov 14 06:47:31 2011] [notice] caught SIGTERM, shutting down

根据说明,我在 NginX 中拥有服务器外部 IP,在 apache 位置中拥有本地主机 IP。

然后我停止了 NginX,重新启动了 Apache(再次正常工作),然后当重新启动 NginX 时,错误再次出现:

Restarting nginx: [emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)
[emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)
[emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)
[emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)
[emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)
[emerg]: still could not bind()
nginx.

答案1

从你粘贴的输出可以清楚地看出nginx正在尝试绑定所有可用 IP 地址上的端口 80,而不仅仅是您的公共地址。

你应该仔细检查所有相关指令nginx配置文件。您可以通过运行 来执行此操作grep -r 'listen ' /etc/nginx/*

如果你发现输出如下听80;(没有指定 IP 地址),你应该将其替换为收听 xx.xx.xx.xx:80,其中 xx.xx.xx.xx 是您的公网 IP 地址。

答案2

我遇到了几乎相同的问题。(Ubuntu 10.04,2 个真实 IP,一个用于 Apache,一个用于 nginx)。解决方案:每个服务器 {...}配置文件中的块必须有听 abcd:80 指令。否则,nginx 将尝试使用所有可用的 IP。

相关内容