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've a little problem with nginx, acting both as reverse proxy and proxified server.

On the front server, my configuration is:

server {
        server_name example.com;

        location / {
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_pass http://10.2.2.1:8999;
        }
}

And on the proxified server:

server {
    listen 10.2.2.1:8999;

    server_name example.com;
    autoindex on;

    location / {
        root /var/www/;
    }
}

Finally, on this proxified server, a directory /var/www/test exists with some files inside.

The problem occurs when I try to access to http://example.com/test (without trailing slash!): my browser is redirected to http://example.com:8999/test/... If I try to access to http://example.com/test/, no problem.

I've tried proxy_redirect statement which, from what I understand, allow the reverse proxy to rewrite Location header to avoid this kind of behavior, but this didn't worked for me. why?.

My second question is, why profixied nginx redirect me to this URL ? How I can prevent it to do that ?

Thanks by advance for any help.

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

Turn off port_in_redirect on the backend server.

share|improve this answer
    
Thanks, I hadn't seen this option ! But the nginx redirection can it be disabled ? –  Antoine Jul 18 '11 at 18:40
    
What would you want it to do if /test is requested? Return a 404? It won't generate the directory index without the trailing slash. –  kolbyjack Jul 18 '11 at 19:26
add comment

Your Answer

 
discard

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

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