Welcome! Log In Create A New Profile

Advanced

Re: proxy if cookie + map

Валентин Бартенев
August 28, 2014 12:28PM
On Thursday 28 August 2014 10:36:36 sejo412 wrote:
> Спасибо, решение уже где-то рядом )
> На боевом сервере за все отвечает php-скрипт.
> Сделал так:
> location / {
> if ($http_cookie ~ 'newsitetest') {

Зачем так усложнять.
В nginx есть специальные переменные для работы с куками: $cookie_*.

К изучению: http://nginx.org/ru/docs/http/ngx_http_core_module.html#variables


> rewrite ^ /newsite/$uri last;
> }
> rewrite / /not_found.php?query_uri=/&$args;
> }
>
> location ~* ^/(.+)$ {

Вам не нужен этот location с регуляркой.


> if ($http_cookie ~ 'newsitetest') {
> rewrite ^ /newsite/$uri last;
> }
>
> try_files $uri $uri/ /not_found.php?query_uri=/$1&$args;
> fastcgi_pass 127.0.0.1:9000;
> fastcgi_index index.html;
> include fastcgi_params;
> fastcgi_param SCRIPT_FILENAME
> $document_root$fastcgi_script_name;
> fastcgi_param QWERTY $document_root$fastcgi_script_name;
> }
>
> location /newsite/ {
> proxy_pass http://192.168.2.146;

Есть большая разница между:

proxy_pass http://192.168.2.146;

и

proxy_pass http://192.168.2.146/;

К изучению: http://nginx.org/r/proxy_pass/ru

> proxy_http_version 1.1;
> proxy_set_header Connection "";
> proxy_set_header Host $host;
> proxy_set_header X-Real-IP $remote_addr;
> proxy_set_header X-Forwarded-For
> $proxy_add_x_forwarded_for;
> }
>
> После установки куки браузер выдает 500 ошибку, в логах nginx (который
> проксирует) ругань на циклический редирект
> 2014/08/28 18:21:51 [error] 19193#0: *454 rewrite or internal redirection
> cycle while processing
>
"/newsite//newsite//newsite//newsite//newsite//newsite//newsite//newsite//newsite//newsite//not_found.php"
>

Ваш конфиг целиком должен выглядеть так:

location / {

if ($cookie_newsitetest) {
rewrite ^ /newsite/$uri last;
}

try_files $uri $uri/ /not_found.php?query_uri=$uri&$args;

fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.html;

include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param QWERTY $document_root$fastcgi_script_name;
}

location /newsite/ {
internal;

proxy_pass http://192.168.2.146/;
proxy_http_version 1.1;

proxy_set_header Connection "";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

--
Валентин Бартенев
_______________________________________________
nginx-ru mailing list
nginx-ru@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-ru
Subject Author Posted

proxy if cookie + map

Синицкий Павел Евгеньевич August 28, 2014 07:44AM

Re: proxy if cookie + map

Илья Шипицин August 28, 2014 08:40AM

Re: proxy if cookie + map

sejo412 August 28, 2014 10:01AM

Re: proxy if cookie + map

Валентин Бартенев August 28, 2014 08:42AM

Re: proxy if cookie + map

sejo412 August 28, 2014 10:36AM

Re: proxy if cookie + map

Валентин Бартенев August 28, 2014 12:28PM

Re: proxy if cookie + map

sejo412 August 29, 2014 08:56AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

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