Welcome! Log In Create A New Profile

Advanced

Re: redirect loop with try_files

Francis Daly
May 04, 2013 04:58PM
On Sat, May 04, 2013 at 10:20:32AM -0400, mschipperheyn wrote:

Hi there,

> ## Rewrite index requests
> rewrite ^(.*)/index.(.*)$ $1/ permanent;

That is likely to lead to a loop, unless you take great care elsewhere.

(The typical defaults are: a request for /dir/ leads to an internal
rewrite to /dir/index.html, which the above would convert to an external
redirect to /dir/, which is where we came in.)

> location = / {
> set $red 0;
> if ($http_cookie ~* "JSESSIONID"){
> set $red 1;
> }

Here, you use "if" inside "location" and you do something other than
"return" or "rewrite ... last". That's rarely a good idea:

http://wiki.nginx.org/IfIsEvil

Can you move the if/set logic to server{} level, to avoid that likely
confusion?

> When a users types in domain www.site.com, he ends up in an endless loop.

I strongly suspect that the loop is caused by the first rewrite, because
the try_files does not apply because at least one of your "if" conditions
is true.

You can test that by trying "curl -i http://www.site.com/", and adding
whatever is necessary to make sure that none of the "if" conditions match,
and seeing if you get anything different.

Or you can just redo the configuration to avoid most "if" inside
"location" blocks.

f
--
Francis Daly francis@daoine.org

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

redirect loop with try_files

mschipperheyn May 04, 2013 10:20AM

Re: redirect loop with try_files

Francis Daly May 04, 2013 04:58PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 118
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready