1

Regardless of what I do, Nginx keeps breaking my url's. I believe this only occurs when the response contains a redirect. I believe I have tried every combination of suggestions from the wiki and the first 20 or so pages on google by now to no avail.

My configuration looks something like this:

upstream tomcat {
    server 10.0.0.1:8080;
}
upstream opsview {
    server 127.0.0.1:3000;
}

server {
    listen 80;
    server_name example.com;

    location / {
        proxy_pass     http://tomcat/;
        proxy_redirect http://tomcat/ /;
        server_name_in_redirect off;

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

I have tried:

  1. both upstreams (and they behave differently)
  2. passing and redirecting directly to the ip:port instead of to an upstream
  3. with and without trailing slashes
  4. proxy_redirect off
  5. with and without the server_name_in_redirect off
  6. with and without the header directives

The error cases that keep coming back:

  • If proxying to an external host, I am liable to find my browser literally redirected to http://tomcat/.
  • If proxying to another service on the same host, I am liable to find my browser redirected to the other port: http://example.com:3000/.

What on earth am I doing wrong?

1 Answer 1

1

You should check what really upstream returns in Location: HTTP header when it does redirect. It is possible that Location: has URL like http://tomacat.fully.qualifyed.name/somepath/ and this wont match proxy_redirect http://tomcat/ /.

1
  • That sounds like the most reasonable answer I've come across so far, thanks.
    – allaryin
    Jun 12, 2011 at 4:15

Not the answer you're looking for? Browse other questions tagged or ask your own question.