Nginx 502 Bad Gateway Node JS

时间:2014-01-07 18:44:14

标签: node.js amazon-web-services nginx amazon-elb

我在亚马逊有一个ELB设置,它指向运行Nginx的两台服务器。然后,Nginx将请求本地转发到运行我们的Node JS应用程序的不同端口。

当我正在测试冗余时,如果我停止运行Node JS应用程序,Nginx将返回一个我完全期望的502 Bad Gateway。我遇到的问题是如何让ELB确定这是一个糟糕的页面,它应该停止向有问题的服务器发送请求? ELB似乎将Nginx 502错误视为有效的HTTP请求,因此不会将其删除。

ELB监视器不显示任何500错误

编辑:

Nginx config:
server {
  listen 80;
  server_name  *.domain.com XX.XX.XX.XX;
  access_log  off;
  client_max_body_size 2048M;
  rewrite ^(.*) https://$host$1 permanent;
  add_header X-Whom USE1A-01;
}

server {
 listen 443;
 ssl on;
 ssl_certificate /ssl.crt;
 ssl_certificate_key /ssl.key;
 server_name *.domain.com XX.XX.XX.XX;

 access_log  off;
 client_max_body_size 2048M;

 location / {
   proxy_set_header Host $host;
   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
   proxy_set_header X-Forwarded-Proto https;
   proxy_set_header Host $host;
   proxy_pass https://127.0.0.1:XXXX;
 }
}

当应用未运行时,我的nginx访问日志显示为运行状况检查:

10.50.101.244 - - [07/Jan/2014:21:31:24 +0000] "-" 400 0 "-" "-"
10.50.101.244 - - [07/Jan/2014:21:31:34 +0000] "GET /healthCheck HTTP/1.1" 200 151 "-" "ELB-HealthChecker/1.0"
10.50.101.244 - - [07/Jan/2014:21:31:54 +0000] "-" 400 0 "-" "-"
10.50.101.244 - - [07/Jan/2014:21:32:04 +0000] "GET /healthCheck HTTP/1.1" 200 151 "-" "ELB-HealthChecker/1.0"
10.50.101.244 - - [07/Jan/2014:21:32:24 +0000] "-" 400 0 "-" "-"
10.50.101.244 - - [07/Jan/2014:21:32:34 +0000] "GET /healthCheck HTTP/1.1" 200 151 "-" "ELB-HealthChecker/1.0"
10.50.101.244 - - [07/Jan/2014:21:32:54 +0000] "-" 400 0 "-" "-"
10.50.101.244 - - [07/Jan/2014:21:33:04 +0000] "GET /healthCheck HTTP/1.1" 200 151 "-" "ELB-HealthChecker/1.0"
10.50.101.244 - - [07/Jan/2014:21:33:24 +0000] "-" 400 0 "-" "-"
10.50.101.244 - - [07/Jan/2014:21:33:34 +0000] "GET /healthCheck HTTP/1.1" 200 151 "-" "ELB-HealthChecker/1.0

2 个答案:

答案 0 :(得分:0)

502 Bad Gateway Deploying Express Generator Template on Elastic Beanstalk

“已解决。我相信这里的问题是AWS在npm启动之前正在进行节点app.js。节点app.js没有出错,但它没有打开任何端口。所以解决方案是重命名app.js到其他任何东西(我使用了main.js)并在bin / www中引用它。它现在正常工作。“

答案 1 :(得分:0)

https://www.ibm.com/cloud/blog/node-js-502-bad-gateway-issues-and-how-to-resolve-them,添加:

"engines": {
    "node": "^7.10.0"
}

到我的 package.json(然后重新运行 npm install 以进行良好测量并重新启动我的应用程序)似乎解决了问题,可能是因为我现在遇到了“未找到”错误。

相关问题