Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to get the nxinx load balancer to work. I have the following configuration:

upstream backend {
  server max_fails=3 fail_timeout=60s;
  server max_fails=3 fail_timeout=60s;

server {
  listen 80;

  access_log /var/log/nginx/app/access.log combined;
  error_log /var/log/nginx/app/error.log;

  location / {
    include /etc/nginx/proxy_params;
    proxy_pass http://backend;


where /etc/nginx/proxy_params is the default:

proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

When the load balancer gets a redirect (as some of the pages on the site will do), it includes port 8001 in the redirect, e.g. instead of

How can I fix this? I've tried setting proxy_redirect to off, but it has no effect.

share|improve this question
This sounds like your application is causing the problem. – Michael Hampton Jan 31 '14 at 17:43
@MichaelHampton Can you be more specific? Is there some header that the application should be sending? From a web search, this seems like a common problem with nginx, but none of the suggested solutions appear to work. – Rob Jan 31 '14 at 17:51
nginx doesn't generate the redirects, your application does. Therefore it's most likely generating incorrect redirects. – Michael Hampton Jan 31 '14 at 18:06
Try this: Nginx solution for Apache ProxyPassReverse. Not putting this as an answer because I'm far too lazy to elaborate on this. – yoonix Jan 31 '14 at 18:41
@MichaelHampton The application is redirecting as if the user agent is connected directly to it, which is what the application should be doing. nginx is rewriting the Location headers in redirects, but it is not changing the port. So it seems that the problem is nginx or how it is configured. – Rob Feb 3 '14 at 8:55

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.