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

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 {
upstream opsview {

server {
    listen 80;

    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:

What on earth am I doing wrong?

share|improve this question
up vote 1 down vote accepted

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

share|improve this answer
That sounds like the most reasonable answer I've come across so far, thanks. – allaryin Jun 12 '11 at 4:15

protected by Tom O'Connor Sep 17 '13 at 7:21

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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