0

I have a API First app that has separate servers for the front end and back end.

The frontend is just an NGINX server that serves a static Angular site. The backend is a Play Scala server.

Recently, to avoid having to use CORS anymore, I made anything sent to /api forward to api.myapp.com using a block like this:

location /api/ {

    proxy_pass https://api.myapp.com/;

}

Everything seems to work fine, except every once in a while the frontend server stops passing requests anymore, and just keeps returning 502s although some requests get through.

If I restart the NGINX server, everything is fine.

If I look at the NGINX logs, I see a bunch of 499 errors for the /api requests.

[15/Jan/2017:22:31:18 +0000] "GET /api/1/users/tzXWM4hNAHUvT9SfA-pAGA/organizations?v=3 HTTP/1.1" 499 0 "https://app.myapp.com/dashboard" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36" "10.225.158.152"

If I look at the backend logs, the requests that return 502 never actually make it to the backend.

Would NGINX be throttling some URLs somehow or thinking the backend server is gone for some reason?

I know in Apache to do something similar I had to set retry=0 for the ProxyPass directive.

cdmckay
  • 101
  • 1
  • 9
  • 502 means bad gateway, which means Nginx got an invalid response from the upstream server. http://stackoverflow.com/questions/5011632/502-http-status-code 499 is Nginx specific http://stackoverflow.com/questions/12973304/nginx-499-error-codes – Tim Jan 21 '17 at 21:11
  • There's no 502 in your logs provided, there's 499. 499 is an internal nginx code meaning that the client talking to the nginx cancelled the request, so you have to investigate this issue further. – drookie Jan 21 '17 at 21:11
  • Plus, you probably need to enhance your nginx log format in order to see what backend has reply with. – drookie Jan 21 '17 at 21:12
  • @drookie I see that the log says 499, but the browser sees a 502 error, not 409- does NGINX convert it before display? – cdmckay Jan 21 '17 at 21:51
  • 1
    @drookie Also, if the upstream server is returning an invalid response, why does restarting NGINX fix it? – cdmckay Jan 21 '17 at 21:51
  • The answer is in your logs, only that yours aren't detailed enough to answer these decent questions. You should log the backend response code and the request serve time to get to these. – drookie Jan 21 '17 at 22:56

0 Answers0