Welcome! Log In Create A New Profile

Advanced

Re: не срабатывает if в location

May 06, 2011 02:08PM
On Fri, May 06, 2011 at 06:29:52PM +0300, Dobrozhansky Sergey wrote:
> Имею следуюзий конфиг:
>
> map $http_user_agent $players {
> default 1;
> "~mplayer|vlc|nsplayer" 0;
> }
>
> server {
> location /pl/ {
>
> if ($players) {
> return 444;
> }
>
> location ~ ^/pl/([0-9]+)$ {
> proxy_pass http://127.0.0.1:4026/$1;
> }
>
> location ~ ^/pl/([0-9]+)$ {
> proxy_pass http://127.0.0.1:4026/$1;
> }
>
> }
> }
>
> Если if ($players) { return 444; } расположен внутри location /pl/, то
> он не срабатывает.
>
> Если его вынести из location /pl/ - работает.
> Вот пример рабочего конфига:
>
> server {
>
> if ($players) {
> return 444;
> }
>
> location /pl/ {
>
> location ~ ^/pl/([0-9]+)$ {
> proxy_pass http://127.0.0.1:4026/$1;
> }
>
> location ~ ^/pl/([0-9]+)$ {
> proxy_pass http://127.0.0.1:4026/$1;
> }
>
> }
> }
>
> Версия nginx-1.0.1.

Потому что nginx сначала ищет location, а потом выполняет в нём "if".

Здесь
location ~ ^/pl/([0-9]+)$ {
proxy_pass http://127.0.0.1:4026/$1;
}

регулярное выражение не нужно:

location /pl/ {
proxy_pass http://127.0.0.1:4026/;
}


--
Igor Sysoev

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

не срабатывает if в location

Dobrozhansky Sergey May 06, 2011 11:32AM

Re: не срабатывает if в location

Igor Sysoev May 06, 2011 02:08PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 294
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