我的服务器在nginx代理上与Node JS一起运行时出现502 Bad Gateway错误 [英] 502 Bad Gateway error for my server running with Node JS on nginx proxy

查看:743
本文介绍了我的服务器在nginx代理上与Node JS一起运行时出现502 Bad Gateway错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到502错误的网关错误:当我检查nginx错误日志时,我发现了这一点:

I am getting 502 bad gateway error: when I check the nginx error log I find this:

2017/05/06 02:36:04 [错误] 48176#0:* 135 connect()失败(111:连接被拒绝),同时连接到上游,客户端:10.163.XX.X,服务器:abc-def -ghi,请求:"GET/favicon.ico HTTP/1.1",上游:" https://127.0. 0.1:5300/favicon.ico ",主机:"hostnname",引荐来源网址:"hostname-1

2017/05/06 02:36:04 [error] 48176#0: *135 connect() failed (111: Connection refused) while connecting to upstream, client: 10.163.XX.X, server: abc-def-g request: "GET /favicon.ico HTTP/1.1", upstream: "https://127.0.0.1:5300/favicon.ico", host: "hostnname", referrer: "hostname-1

我对互联网进行了足够的搜索,但找不到任何内容.这里要注意的一件事是,这种间歇性错误仅在特定页面上出现.

I searched internet enough but could not find anything. One thing to note here is that, this intermittent error is coming only on a particular page.

这可能是代码问题吗?或nginx配置问题>任何人都可以在这里帮助我.

Could this be a code issue? or nginx configuration issue> Can anyone please help me here.

我的一些Nginx conf:

Some of my nginx conf:

  upstream node_api_server {
    server localhost:5300 fail_timeout=0;
  }

location / {
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header Host $http_host;
    proxy_set_header X-NginX-Proxy true;
    proxy_read_timeout 5m;
    proxy_connect_timeout 5m;
    proxy_pass_header Set-Cookie;

    proxy_pass https://node_api_server;
    proxy_redirect off;
    proxy_buffer_size   128k;
    proxy_buffers   4 256k;
    proxy_busy_buffers_size   256k;
    break;
}

推荐答案

502错误通常是由NGINX无法将请求传递到上游"引起的,在这种情况下,这是您的Node.js服务器(这也是错误所在消息提示:连接被拒绝" ").

502 errors are generally caused by NGINX being unable to pass a request to "upstream", in this case your Node.js server (which is also what the error message suggests: "Connection refused"").

它可能崩溃并重新启动,因此请检查其日志文件以查看导致崩溃的原因.

It may be crashing and restarting, so check its logfiles to see what's causing the crashes.

这篇关于我的服务器在nginx代理上与Node JS一起运行时出现502 Bad Gateway错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆