简体   繁体   English

Nginx 502 错误的网关节点 JS

[英]Nginx 502 Bad Gateway Node JS

I have a ELB setup in Amazon that's pointing to two servers that are running Nginx.我在 Amazon 中有一个 ELB 设置,它指向两台运行 Nginx 的服务器。 Nginx is then forwarding the request locally to a different port that runs our Node JS application.然后 Nginx 在本地将请求转发到运行我们的 Node JS 应用程序的不同端口。

As I'm testing for redundancy, if I stop the Node JS application from running, Nginx will return a 502 Bad Gateway which I fully expect.当我测试冗余时,如果我停止运行 Node JS 应用程序,Nginx 将返回一个我完全期望的 502 Bad Gateway。 The problem I'm having is how can I have the ELB determine that this is a bad page and that it should stop sending requests to a problematic server?我遇到的问题是如何让 ELB 确定这是一个错误页面并且它应该停止向有问题的服务器发送请求? The ELB seems to see the Nginx 502 error as a valid HTTP request and thus won't remove it. ELB 似乎将 Nginx 502 错误视为有效的 HTTP 请求,因此不会将其删除。

the ELB monitor doesn't show any 500 errors either ELB 监视器也不显示任何 500 错误

EDIT:编辑:

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;
 }
}

What my nginx access log is showing for the health check when the app is NOT running:当应用程序未运行时,我的 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

Per 502 Bad Gateway Deploying Express Generator Template on Elastic Beanstalk ,根据502 Bad Gateway 在 Elastic Beanstalk 上部署 Express Generator 模板

"Solved. I believe the issue here was that AWS was doing node app.js BEFORE npm start. node app.js doesn't give an error, but it doesn't open any ports. So the solution was to rename app.js to anything else (I used main.js) and reference that in bin/www. It's now working correctly." “解决了。我相信这里的问题是 AWS 在 npm 启动之前正在执行 node app.js。node app.js 没有给出错误,但它没有打开任何端口。所以解决方案是重命名 app.js到其他任何东西(我使用 main.js)并在 bin/www 中引用它。它现在可以正常工作了。”

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

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

to my package.json (and then re-running npm install for good measure and restarting my app) seemed to solve the problem, probably, since I'm now experiencing a "Not Found" error.到我的package.json (然后重新运行npm install以进行良好的测量并重新启动我的应用程序)似乎解决了问题,可能,因为我现在遇到了“未找到”错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM