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.
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.
I’ve enabled debugging and the output is here: http://pastebin.com/Dmw2nJMY. I’ve cleared all caches and restarted
varnish, nginx and php5-fpm and mysql.
I didn’t explain myself very well earlier. The “fastcgi_param
SERVER_PORT 80” does work for php pages (it’s in my location ~ .php$
block) but the problem I’m having is with my server root.
One thing I noticed is “location /” block is used first, the index.php
is tried, and then the “location ~ .php$” block processes this page. I
would have thought that the SERVER_PORT would have rewritten the port
used at this stage…?
You can try tricking php by putting $_SERVER[“SERVER_PORT”] right at
the top of your index php (or use autoprepend in php.ini so it applies
to all php files).
That should read - You can try tricking php by putting
$_SERVER[“SERVER_PORT”] = “80”;
I’ve enabled debugging and the output is here: http://pastebin.com/Dmw2nJMY. I’ve cleared all caches and restarted
varnish, nginx and php5-fpm and mysql.
Line 245 of your debug shows the issue. php is sending a header - http
fastcgi header: “Location: http://XXX.XXX.XXX.XXX:8080/”. The
proxy_redirect directive handles this for proxy_pass setups but there
isn’t an equivalent for fastcgi.
You can try tricking php by putting $_SERVER[“SERVER_PORT”] right at
the top of your index php (or use autoprepend in php.ini so it applies
to all php files).
I just had a problem with this with a proxy setup as the
proxy_redirect only accepts variables in the redirect part such that I
had to do …