Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

upstream backend {
  server app-1.example.com:8001 max_fails=3 fail_timeout=60s;
  server app-2.example.com:8001 max_fails=3 fail_timeout=60s;
}

server {
  listen 80;
  server_name app.example.com;

  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. http://app.example.com:8001/some/url instead of http://app.example.com/some/url.

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 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 at 17:51
1  
nginx doesn't generate the redirects, your application does. Therefore it's most likely generating incorrect redirects. –  Michael Hampton Jan 31 at 18:06
1  
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 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 at 8:55

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.