3

I have a ELB setup in Amazon that's pointing to two servers that are running Nginx. Nginx is then forwarding the request locally to a different port that runs our Node JS application.

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. 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? The ELB seems to see the Nginx 502 error as a valid HTTP request and thus won't remove it.

the ELB monitor doesn't show any 500 errors either

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:

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
nocode
  • 1,238
  • 1
  • 15
  • 21
  • How is your health check configured? Does your health check do a request which will go all the way through to your node.js application? – datasage Jan 08 '14 at 15:53
  • Yes, I have a specific page /healthCheck that will do a simple check on the database. If I stop the application, Nginx shows the 502 bad gateway. Problem is, it does NOT go to the nginx error log - it shows up in the nginx access logs. I believe the ELB is NOT seeing this as an error and I'm not sure how to configure Nginx in a way to make that identification to the ELB. I've added some info to the post – nocode Jan 08 '14 at 16:37
  • The ELB is getting a 200 code response. Which is why its not failing. Is the health check going over http or https? – datasage Jan 08 '14 at 17:43
  • HTTP. Since I'm redirecting all requests to HTTPS, that's what I need to do then? – nocode Jan 08 '14 at 17:46
  • Ok that worked switching it to HTTPS on the ELB. Thanks! – nocode Jan 08 '14 at 18:02

2 Answers2

0

Per 502 Bad Gateway Deploying Express Generator Template on Elastic Beanstalk,

"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."

Community
  • 1
  • 1
Federico
  • 6,388
  • 6
  • 35
  • 43
0

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

"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.

Ryan
  • 22,332
  • 31
  • 176
  • 357