Welcome! Log In Create A New Profile

Advanced

rewrite cycle

Posted by Руслан Закиров 
Руслан Закиров
rewrite cycle
December 15, 2016 12:40PM
Hi,

Below is default foswiki config that falls into "rewrite or internal
redirection cycle while processing
"/bin/view/bin/view/bin/view/bin/view/bin/view/bin/view/bin/view/bin/view/bin/view/bin/view/Main/WebHome"".

This is Nginx 1.11.6.

Any ideas?

location = / {
root $foswiki_root;
rewrite .* /Main/WebHome;
}
location ~ ^/([A-Z_].*)$ {
rewrite ^/(.*)$ /bin/view/$1;
}
location ~ ^/bin/([a-z]+) {
fastcgi_param SCRIPT_NAME $1;
gzip off;
#fastcgi_pass unix:/var/run/nginx/foswiki.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(/bin/\w+)(.*);
fastcgi_param SCRIPT_FILENAME
$foswiki_root/$fastcgi_script_name;
fastcgi_param SCRIPT_NAME
$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
include fastcgi_params;
}

Debug log:

2016/12/15 14:24:02 [debug] 15695#0: *6 test location: "/"
2016/12/15 14:24:02 [debug] 15695#0: *6 using configuration "=/"
2016/12/15 14:24:02 [debug] 15695#0: *6 http cl:-1 max:104857600
2016/12/15 14:24:02 [debug] 15695#0: *6 rewrite phase: 2
2016/12/15 14:24:02 [debug] 15695#0: *6 http script regex: ".*"
2016/12/15 14:24:02 [notice] 15695#0: *6 ".*" matches "/", client:
127.0.0.1, server: wiki.sports.ru, request: "GET / HTTP/1.1", host: "
wiki.sports.ru"
2016/12/15 14:24:02 [debug] 15695#0: *6 http script copy: "/Main/WebHome"
2016/12/15 14:24:02 [debug] 15695#0: *6 http script regex end
2016/12/15 14:24:02 [notice] 15695#0: *6 rewritten data: "/Main/WebHome",
args: "", client: 127.0.0.1, server: wiki.sports.ru, request: "GET /
HTTP/1.1", hos
t: "wiki.sports.ru"
2016/12/15 14:24:02 [debug] 15695#0: *6 post rewrite phase: 3
2016/12/15 14:24:02 [debug] 15695#0: *6 uri changes: 11
2016/12/15 14:24:02 [debug] 15695#0: *6 test location: "/"
2016/12/15 14:24:02 [debug] 15695#0: *6 test location: ~ "^/([A-Z_].*)$"
2016/12/15 14:24:02 [debug] 15695#0: *6 using configuration "^/([A-Z_].*)$"
2016/12/15 14:24:02 [debug] 15695#0: *6 http cl:-1 max:104857600
2016/12/15 14:24:02 [debug] 15695#0: *6 rewrite phase: 2
2016/12/15 14:24:02 [debug] 15695#0: *6 http script regex: "^/(.*)$"
2016/12/15 14:24:02 [notice] 15695#0: *6 "^/(.*)$" matches "/Main/WebHome",
client: 127.0.0.1, server: wiki.sports.ru, request: "GET / HTTP/1.1", host:
"wiki
..sports.ru"
2016/12/15 14:24:02 [debug] 15695#0: *6 http script copy: "/bin/view/"
2016/12/15 14:24:02 [debug] 15695#0: *6 http script capture: "Main/WebHome"
2016/12/15 14:24:02 [debug] 15695#0: *6 http script regex end
2016/12/15 14:24:02 [notice] 15695#0: *6 rewritten data:
"/bin/view/Main/WebHome", args: "", client: 127.0.0.1, server:
wiki.sports.ru, request: "GET / HTTP/1.1", host: "wiki.sports.ru"
2016/12/15 14:24:02 [debug] 15695#0: *6 post rewrite phase: 3
2016/12/15 14:24:02 [debug] 15695#0: *6 uri changes: 10
2016/12/15 14:24:02 [debug] 15695#0: *6 test location: "/"
2016/12/15 14:24:02 [debug] 15695#0: *6 test location: ~ "^/([A-Z_].*)$"
2016/12/15 14:24:02 [debug] 15695#0: *6 using configuration "^/([A-Z_].*)$"
2016/12/15 14:24:02 [debug] 15695#0: *6 http cl:-1 max:104857600
2016/12/15 14:24:02 [debug] 15695#0: *6 rewrite phase: 2
2016/12/15 14:24:02 [debug] 15695#0: *6 http script regex: "^/(.*)$"
2016/12/15 14:24:02 [notice] 15695#0: *6 "^/(.*)$" matches
"/bin/view/Main/WebHome", client: 127.0.0.1, server: wiki.sports.ru,
request: "GET / HTTP/1.1", host: "wiki.sports.ru"
2016/12/15 14:24:02 [debug] 15695#0: *6 http script copy: "/bin/view/"
2016/12/15 14:24:02 [debug] 15695#0: *6 http script capture:
"bin/view/Main/WebHome"
2016/12/15 14:24:02 [debug] 15695#0: *6 http script regex end
2016/12/15 14:24:02 [notice] 15695#0: *6 rewritten data:
"/bin/view/bin/view/Main/WebHome", args: "", client: 127.0.0.1, server:
wiki.sports.ru, request: "GET / HTTP/1.1", host: "wiki.sports.ru"
2016/12/15 14:24:02 [debug] 15695#0: *6 post rewrite phase: 3


--
Руслан Закиров
Руководитель отдела разработки веб-сервисов
+7(916) 597-92-69, ruz @ http://www.sports.ru/
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Francis Daly
Re: rewrite cycle
December 15, 2016 02:20PM
On Thu, Dec 15, 2016 at 02:30:17PM +0300, Руслан Закиров wrote:

Hi there,

> Below is default foswiki config that falls into "rewrite or internal
> redirection cycle while processing
> "/bin/view/bin/view/bin/view/bin/view/bin/view/bin/view/bin/view/bin/view/bin/view/bin/view/Main/WebHome"".
>
> This is Nginx 1.11.6.
>
> Any ideas?

It seems to do what it is configured to do.

What do you want it to do instead?

> location = / {
> root $foswiki_root;
> rewrite .* /Main/WebHome;
> }
> location ~ ^/([A-Z_].*)$ {
> rewrite ^/(.*)$ /bin/view/$1;
> }

One possibility it to change that location regex, which is currently
"everything", to instead be only what is wanted.

> location ~ ^/bin/([a-z]+) {

Another possibility is to move this location above the "regex everything"
one, so that most things that start with /bin/ will use this instead of
the other.

Cheers,

f
--
Francis Daly francis@daoine.org
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Maxim Dounin
Re: rewrite cycle
December 15, 2016 03:10PM
Hello!

On Thu, Dec 15, 2016 at 02:30:17PM +0300, Руслан Закиров wrote:

> Below is default foswiki config that falls into "rewrite or internal
> redirection cycle while processing
> "/bin/view/bin/view/bin/view/bin/view/bin/view/bin/view/bin/view/bin/view/bin/view/bin/view/Main/WebHome"".
>
> This is Nginx 1.11.6.
>
> Any ideas?
>
> location = / {
> root $foswiki_root;
> rewrite .* /Main/WebHome;
> }
> location ~ ^/([A-Z_].*)$ {
> rewrite ^/(.*)$ /bin/view/$1;
> }
> location ~ ^/bin/([a-z]+) {

[...]

> 2016/12/15 14:24:02 [notice] 15695#0: *6 rewritten data: "/bin/view/Main/WebHome", ...

[...]

> 2016/12/15 14:24:02 [debug] 15695#0: *6 test location: ~ "^/([A-Z_].*)$"
> 2016/12/15 14:24:02 [debug] 15695#0: *6 using configuration "^/([A-Z_].*)$"

The configuration in question relies on case-sensitive location
matching and won't work correctly with case-insensitive location
matching nginx uses on Windows and macOS. As per the debug log,
it looks like case-insensitive location matching is used in your
case.

--
Maxim Dounin
http://nginx.org/
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Руслан Закиров
Re: rewrite cycle
December 15, 2016 04:20PM
On Thu, Dec 15, 2016 at 5:08 PM, Maxim Dounin <mdounin@mdounin.ru> wrote:

> [...]
>
> > 2016/12/15 14:24:02 [notice] 15695#0: *6 rewritten data:
> "/bin/view/Main/WebHome", ...
>
> [...]
>
> > 2016/12/15 14:24:02 [debug] 15695#0: *6 test location: ~ "^/([A-Z_].*)$"
> > 2016/12/15 14:24:02 [debug] 15695#0: *6 using configuration
> "^/([A-Z_].*)$"
>
> The configuration in question relies on case-sensitive location
> matching and won't work correctly with case-insensitive location
> matching nginx uses on Windows and macOS. As per the debug log,
> it looks like case-insensitive location matching is used in your
> case.
>

Yep, it's Mac OS. Solved by turning off case insensitivity with (?-i).

location ~ ^(?-i)/[A-Z_].*$ {
....
}

Didn't know about this aspect of nginx on Mac and Win.

--
Руслан Закиров
Руководитель отдела разработки веб-сервисов
+7(916) 597-92-69, ruz @ http://www.sports.ru/
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Francis Daly
Re: rewrite cycle
December 29, 2016 12:10PM
On Thu, Dec 15, 2016 at 01:18:55PM +0000, Francis Daly wrote:
> On Thu, Dec 15, 2016 at 02:30:17PM +0300, Руслан Закиров wrote:

Hi there,

You got the right answer from Maxim.

I had missed that

> > location ~ ^/([A-Z_].*)$ {
> > rewrite ^/(.*)$ /bin/view/$1;
> > }

that location was intended to skip "starts with lower case letter".

Sorry about that.

Cheers,

f
--
Francis Daly francis@daoine.org
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Sorry, only registered users may post in this forum.

Click here to login