modify response code based on upstream response

Jeremy Piven jeremypiven at
Sun Sep 28 20:51:22 UTC 2014

I have a set of webservers with nginx acting as a reverse proxy for
tomcat behind an AWS ELB. 

Request -> AWS ELB -> Nginx -> Tomcat

To understand if my application is healthy or not I have to send a
request for /status/health. If "health:0" comes back it means the server
is not ready to serve traffic. If "health:1" comes back it means the
server is ready to serve traffic. Unfortunately, in both scenarios the
http response code is always 200. Since AWS ELB has a dumb healthcheck
method I can't place a server in or out of rotation based on the actual
response output. AWS only considers http response code.

Is it possible to have Nginx modify the http response code based on the
upstream output? I want to basically say if the tomcat response is
"health:0" return an http response code 503.

  Jeremy Piven
  jeremypiven at

More information about the nginx mailing list