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.

when accessing: http://example.com/somefolder --> http://example.com:8080/somefolder

I have tried this:

 http {
    port_in_redirect off;

Any ideas?

share|improve this question
Can you provide your configuration? Are you proxying to another service behind nginx? –  Shane Madden Jan 18 '12 at 20:46
I believe we are are proxying to apache. Which configuration files do you want? –  Chris Muench Jan 18 '12 at 21:37
The nginx configuration file that defines the server block which contains the proxy_pass directive. What you're probably going to need will be a proxy_redirect directive - seeing your config should confirm. –  Shane Madden Jan 18 '12 at 22:22

6 Answers 6

This should fix problem. Add proxy_redirect directive right after proxy_pass directive

proxy_redirect http://example.com:8080/ http://example.com/;

share|improve this answer

I just ran into the same problem and port_in_redirect off; actually worked for me, just make sure you use it inside the server {} block.

server {
  listen 8080;
  server_name example.com;

  port_in_redirect off;
  autoindex on;

  location / {
    root /var/www/example.com;
    index index.html;
share|improve this answer


syntax: port_in_redirect [ on|off ]
default: port_in_redirect on
context: http, server, location

Hope this is what you are looking for.

share|improve this answer
I have tried this in the http context with no luck –  Chris Muench Jan 18 '12 at 20:18

I had a similar problem.

Maybe you should use directive proxy_set_header to set the headers' host and location. In my configuration I added proxy_set_header Location $host:80; and all the requests return port 80 now.

share|improve this answer

I would recommend instead adding this to your server block:

rewrite /wp-admin$ $scheme://$host$uri/ permanent;

This was when you go to example.com/wp-admin it will go to example.com/wp-admin rather than going to example.com:8080/wp-admin/ and if you are on CloudFlare DNS for instance it will say the site is down.

I'm using Ubuntu, Nginx and Varnish and this works perfectly now rather than disabling port_in_redirect.

To add, be sure to to restart nginx after:

sudo service nginx restart
share|improve this answer

I ran into the same problem here, and port_in_redirect off; wasn't working for me too.

I've spent a few hours on it and, it may not sound sophisticated, but remember guys to turn off the local cache (check that in HttpFox for example in Firefox)... I suppose the author might have had similar problem.

So if you see something like that beneath... Well, it might had been the problem. http://i.stack.imgur.com/AATvv.png

share|improve this answer
Thanks for the feedback. In the future, please consider using the Comment function for this type of recommendation. –  Felix Frank Jun 17 '14 at 14:52

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.