#1312 closed defect (invalid)
In fastcgi_pass does not correctly handle variables
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | critical | Milestone: | |
Component: | nginx-module | Version: | 1.13.x |
Keywords: | Cc: | ||
uname -a: | Linux XXXXX 3.16.0-4-amd64 #1 SMP Debian 3.16.39-1+deb8u1 (2017-02-22) x86_64 GNU/Linux | ||
nginx -V: | nginx version: nginx/1.13.2 |
Description
I use Debian 8.8 (jessie) php5-fpm 5.6.30 and nginx/1.13.2
My typical config:
server {
listen XX.XX.XX.XX:80;
server_name DOMAIN.ru;
root /var/www/DOMAIN.ru/web;
index index.php index.html index.htm;
set $fastcgipass unix:/var/lib/php5-fpm/webXX.sock;
#set $fastcgipass 127.0.0.1:9031;
#rewrite /phpinfo/(.*)$ /i.php last;
location / {
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
try_files $uri = 404;
include /etc/nginx/fastcgi_params;
fastcgi_pass $fastcgipass; # <---- Problem in use rewrite last
#fastcgi_pass unix:/var/lib/php5-fpm/webXX.sock; # <----- No problem in using rewrite last
fastcgi_param HTTPS $fastcgi_https;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
Today i decided to write a rewrite rule using last and came across an error of the form:
2017/07/07 11:09:19 [error] 15511#15511: *183067 no host in upstream "", client: XX.XX.XX.XX, server: DOMAIN.ru, request: "GET /phpinfo/ HTTP/1.1", host: "DOMAIN.ru"
My simple rewrite:
rewrite /phpinfo/(.*)$ /i.php last;
# cat /var/www/DOMAIN.ru/web/i.php
<?php
echo "OK";
?>
# curl -D - -o /dev/null -s http://DOMAIN.ru/phpinfo/
HTTP/1.1 500 Internal Server Error
Server: nginx
Date: Fri, 07 Jul 2017 06:09:19 GMT
Content-Type: text/html
Content-Length: 186
Connection: close
A detailed study of the problem showed that the whole thing is in the line
fastcgi_pass $fastcgipass;
i will write
fastcgi_pass unix:/var/lib/php5-fpm/webXX.sock;
then is no problem with rewrite
# curl -D - -s http://DOMAIN.ru/phpinfo/
HTTP/1.1 200 OK
Server: nginx
Date: Fri, 07 Jul 2017 06:34:13 GMT
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
OK
Using tcp with php5-fpm does not solve the problem.
set $fastcgipass 127.0.0.1:9031;
Change History (5)
comment:1 by , 7 years ago
comment:2 by , 7 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
See the description of the rewrite directive, the "last" parameter stops processing of the rewrite directives when the rewrite
directive is matched. As such, set $fastcgipass unix:/var/lib/php5-fpm/webXX.sock;
is not executed, the variable $fastcgipass
is never set, and the error occurs when trying to use the variable.
For more information on the rewrite module and its directives, consider reading the documentation. If you have further questions, consider support options available.
comment:3 by , 7 years ago
Что за бред, Максим, вы сами то читали документацию, цитирую:
last - завершает обработку текущего набора директив модуля ngx_http_rewrite_module, после чего ищется новый location, соответствующий изменённому URI;
ТЕКУЩЕГО НАБОРА ДИРЕКТИВ МОДУЛЯ ngx_http_rewrite_module, с чего вдруг установка значения переменной с помощью set, идущая ниже стала игнорироваться?
В дебаге видно, что вначале идет warn
[warn] 23403#23403: *5 using uninitialized "fastcgipass" variable....
а потом
[error] 23403#23403: *5 no host in upstream "", client: XX.XX.XX.XX, server: _, request: "GET /phpinfo/ HTTP/1.1", host: "YY.YY.YY.YY"
то есть все достаточно понятно, установка переменной set была просто проигнорирована - такого не должно быть по логике, rewrite last это же не тупой go to next location, установка переменных на уровне server не должна игнорироваться или я не прав?
comment:4 by , 7 years ago
set - это тоже директива модуля ngx_http_rewrite_module, также как rewrite, return, break, if - всё это инструкции, выполняемые последовательно одна за другой.
comment:5 by , 7 years ago
Ваша правда, беру свои слова назад и извиняюсь за необоснованный наезд.
Значит rewrite last это все же тупой go to next location
An error occurs if
set $fastcgipass unix:/var/lib/php5-fpm/webXX.sock;
written after
rewrite /phpinfo/(.*)$ /i.php last;
and up to
location / {
}
See full bad config:
server {
}