Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

When I access, my browser gets a redirect to

However, it works fine when I access

The backend is an apache server listening on port 8080.

nginx configuration:

server {
        listen 80 default_server;
        location / {

                proxy_set_header X-Real-IP  $remote_addr;
                proxy_set_header X-Forwarded-For $remote_addr;
                proxy_set_header Host $host;
                proxy_redirect default;

I've tried:


Still the same issues. I've looked at similar questions but can't seem to get an answer to this one.

Anyone have any ideas?

share|improve this question
Do you have any other locations which may be taking precedence when called without a trailing slash? P.S. from nginx's POV, if it doesn't end with trailing slash, it's not a folder. – Grumpy Jan 30 '13 at 20:26
Nope. Only location. – Belmin Fernandez Jan 30 '13 at 20:38
Do you actually need the redirect? why not just off? – Grumpy Jan 30 '13 at 20:43

Disable the port_in_redirect option in the configuration.

Syntax:     port_in_redirect <on | off>
Default:    on
Context:    http, server, location

Directive allows or prevents port indication in redirects handled by Nginx. If port_in_redirect is off, then Nginx will not add the port in the URL when the request is redirected.

share|improve this answer
Think you may have answered the question in my answer before I even asked it. Trying this now. – Belmin Fernandez Jan 30 '13 at 20:51
Unfortunately, that didn't work. Looked promising though! – Belmin Fernandez Jan 30 '13 at 20:54
Ah I see. This worked when there was a reverse-proxy in front of Nginx. Maybe you could try to dump the traffic between Nginx and Apache to see what's going on. – Endre Szabo Jan 30 '13 at 20:56
up vote 0 down vote accepted

The issue was that apache's mod_dir module was redirecting non-trailing-slash 403s to the URL with the trailing slash.

Here is documentation on the mod_dir DirectorySlash.

Turning off the directive was a workaround but I like the DirectorySlash feature. Just don't want to expose the apache backend.

After trying some things, I finally came to a working solution by modifying my nginx configuration from this:

proxy_set_header Host $host;
... this:

proxy_set_header Host $host:80;

This did the trick! Hope this helps someone cause it really cause me a lot of headaches.

share|improve this answer

Your Answer


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.