使用 NodeBB 的 nginx 502 错误网关

nginx 502 Bad Gateway with NodeBB

使用我的域连接到我的 NodeBB 安装时,我收到 502 错误网关 NodeBB 在默认端口 (4567)

上 运行

我的 nginx 似乎配置正确(使用 IP 连接时):http://puu.sh/mLI7U/0e03691d4c.png 我的 nodebb 似乎配置正确(使用 IP 连接时): http://puu.sh/mLI95/5fdafcaed9.png 我的 A 记录将 IP 指向我的 VPS 配置正确。

这是我的 etc/nginx/conf.d/example.com.conf

server {
listen 80;

server_name sporklounge.com;

location / {
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_set_header X-NginX-Proxy true;

    proxy_pass http://127.0.0.1:4567/;
    proxy_redirect off;

    # Socket.IO Support
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
}

}

My NodeBB config.json
{
    "url": "http://localhost:4567",
    "secret": "25d0d6a2-0444-49dc-af0c-bd693f5829d8",
    "database": "redis",
    "redis": {
        "host": "127.0.0.1",
        "port": "6379",
        "password": "",
        "database": "0"
    }
}

这是我的 var/log/nginx/error.log

    2016/01/27 12:04:42 [error] 22026#0: *4062 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 50.186.224.26, server: sporklounge.com, request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:80/favicon.ico", host: "sporklounge.com", referrer: "http://sporklounge.com/"
2016/01/27 12:21:06 [crit] 974#0: *1 connect() to 127.0.0.1:4567 failed (13: Permission denied) while connecting to upstream, client: 50.186.224.26, server: sporklounge.com, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:4567/", host: "sporklounge.com"
2016/01/27 12:21:07 [crit] 974#0: *1 connect() to 127.0.0.1:4567 failed (13: Permission denied) while connecting to upstream, client: 50.186.224.26, server: sporklounge.com, request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:4567/favicon.ico", host: "sporklounge.com", referrer: "http://sporklounge.com/"

非常感谢所有帮助,我会回答所有问题以帮助找到解决方案,谢谢!

我看到的一件事是,根据 the docs,您的 url 配置值应该是 完整的 web-accessible 地址,指向您的 NodeBB。那将是 sporklounge.com,而不是当前值。

也可能是后端有时响应缓慢。在 Nginx 中尝试这个值的非常高的值,看看后端是否最终响应:

 # For testing, allow very long response times.
 proxy_read_timeout 5m;

此外,使用 netstat 确认后端 运行 在端口 4567 上:

sudo netstat -nlp | grep ':4567'

等等,答案可能就在您的日志中,这会告诉您连接失败的原因:

(13: Permission denied) while connecting to upstream

参见相关问题:

  • (13: Permission denied) while connecting to upstream:[nginx]