port_in_redirect not working?

Maxim Dounin mdounin at mdounin.ru
Mon Nov 7 17:26:34 UTC 2011


Hello!

On Mon, Nov 07, 2011 at 11:17:28AM -0500, olan wrote:

> 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
> URL. 
> 
> 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
> yet)
> 
>     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 {
>     server 127.0.0.1:9000;
> }
> 
> 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):
> http://stackoverflow.com/questions/8026763/nginx-port-in-redirect-not-working]

The "port_in_redirect" directive only alters behaviour of nginx 
itself (for trailing slash redirects, rewrites and so on), and 
it's expected that it does nothing for redirects returned by php.

With "fastcgi_param SERVER_PORT 80;" php should be fine, and I 
suspect that problem you see is actually related to your browser 
(or varnish) cache sitting here from previous configurations.  

If clearing cache doesn't help, please provide debug log (see 
http://wiki.nginx.org/Debugging), it will show what goes on here.

Maxim Dounin



More information about the nginx mailing list