port_in_redirect not working?

olan nginx-forum at nginx.us
Mon Nov 7 16:17:28 UTC 2011

Hi all,

I posted this question on SO but haven't received much attention, so I
figured here would be better.

Basically I am attempting to run varnish on port 80 and my nginx server
on 8080, however any request to 80 redirects and appends the port to the

i.e. http://site.com/ -> http://site.com:8080/

>From everything I've read it seems that 'port_in_redirect off' should
disable this, however it does not appear to be working. I've used a
workaround for php by using "fastcgi_param SERVER_PORT 80;", which
works, but requests to my "location /" are getting the port appended.

My server setup is:

server { 
    listen 8080 default;
    server_name "" xxx.xxx.xxx.xxx;  #just using IP here (no domain

    port_in_redirect off;
    server_name_in_redirect off;

    access_log  /var/log/nginx/localhost.access.log;

    location / {
            root   /var/www/site/html/;
            index  index index.php;
            try_files $uri/ $uri /index.php?q=$uri&$args;
upstream backend {

I have tried port_in_redirect in both the "location /" and the server
blocks, but neither works.

Can anyone shed any light on this problem? I'm currently using nginx
v1.0.9 on a ubuntu server.

[Link to SO question (full .conf there):

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,217928,217928#msg-217928

More information about the nginx mailing list