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

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;
    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?

share|improve this question

1 Answer 1

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 http://tomacat.fully.qualifyed.name/somepath/ 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 answers, posting an answer now requires 10 reputation on this site.

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.