Welcome! Log In Create A New Profile

Advanced

Неверно передаётся Location

Posted by deatwisedog 
Неверно передаётся Location
October 19, 2016 09:02AM
Добрый день, коллеги! Не выходит настроить правильный редирект средствами php.

nginx.conf:

server {
server_name www.domain.ru;
rewrite ^(.*) http://domain.ru$1 permanent;
}
server {
listen 80;
root /var/www/folder/public;

index index.html index.htm index.php;

server_name anotherdomain.ru subdomain.domain.ru subdomain2.domain.ru domain.ru;


location ~ \.php$ {
# root /var/www

try_files $uri =404;
fastcgi_keep_conn on;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
include /etc/nginx/fastcgi_params;
}

location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}

location ~ /\.ht {
deny all;
}
}

При таком коде:

<?php
header('Location: http://subdomain.domain.ru/');
exit;
?>

В ответ получаю:

[root@svm]# curl -I http://domain.ru/indexfile.php
HTTP/1.1 302 Moved Temporarily
Connection: close
Date: Mon, 17 Oct 2016 13:57:59 GMT
Location: http://domain.ru/
Content-Type: text/html; charset=UTF-8
Server: nginx/1.4.6 (Ubuntu)

Но при этом, в консоли отладки firefox вижу такой Url Запроса: http://domain.ru/subdomain.domain.ru

А при таком коде:

<?php
header('Location: http://subdomain2.domain.ru/');
exit;
?>

Прилетает это:

[root@svm]# curl -I http://domain.ru/indexfile2.php
HTTP/1.1 302 Moved Temporarily
Connection: close
Date: Mon, 17 Oct 2016 13:57:59 GMT
Location: http://subdomain2.domain.ru/
Content-Type: text/html; charset=UTF-8
Server: nginx/1.4.6 (Ubuntu)

Для одного конкретного поддомена не присваивается новый заголовок с location. В чём может быть проблема и как её исправить?

Наблюдение: Если в Location: указывать uri без http (То есть просто //subdomain.domain.ru, то перенаправление работает. Почему? Как исправить?

Интересный факт - Добавил в файл indexfile.php несколько произвольных заголовков и их вывод: "print_r(headers_list());". Судя по всему, php правильно выставляет все заголовки кроме "Location", но они либо не применяются, либо их переписывает nginx:

[root@svm]# curl -v http://domain.ru/indexfile.php
* About to connect() to 4cio.ru port 80 (#0)
* Trying 11.11.11.11...
* Connected to domain.ru (11.11.11.11) port 80 (#0)
> GET /indexfile.php HTTP/1.1
> User-Agent: curl/7.29.0
> Host: domain.ru
> Accept: /
>
< HTTP/1.1 302 Moved Temporarily
< Connection: Keep-Alive
< Transfer-Encoding: chunked
< Expires: Mon, 26 Jul 2666 05:00:00 GMT
< Date: Tue, 18 Oct 2016 14:46:44 GMT
< Location: **http://domain.ru** - Ну вот откуда он берётся?
< Content-Type: text/html; charset=UTF-8
< Server: nginx/1.4.6 (Ubuntu)
< Cache-Control: no-cache
<
Array
(
[0] => Expires: Mon, 26 Jul 2666 05:00:00 GMT
[1] => Cache-Control: no-cache
[2] => Location: http://subdomain.domain.ru
)
Sorry, only registered users may post in this forum.

Click here to login

Online Users

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