port_in_redirect not working?

Nginx User nginx at nginxuser.net
Mon Nov 7 19:44:43 UTC 2011


On 7 November 2011 21:25, olan <nginx-forum at nginx.us> wrote:
> Hi Maxim, thanks for getting back to me.
>
> 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 ....

proxy_redirect   http://example-1.com:8080/    http://example-1.com/;
proxy_redirect   http://example-2.com:8080/    http://example-2.com/;
proxy_redirect   http://example-3.com:8080/    http://example-3.com/;
...
proxy_redirect   http://example-n.com:8080/    http://example-n.com/;

If the directive accepted variables in the original uri part, a single line ...

proxy_redirect   http://$host:8080/    http://$host/;

... would have done the job and given flexibility. I have to remember
to add every domain I create to the list.

Anyway, I digress. Try the trick on PHP. Nothing can be done in Nginx
until a fastcgi_redirect directive is introduced.



More information about the nginx mailing list