今天有部分生产环境服务器的nginx版本升级到nginx.1.20.2后,web日志里产生了大量的错误日志:
2022/04/01 11:40:35 [warn] 47023#0: *673934 using uninitialized "path_info" variable, client: 221.216.116.9, server: m.wdmcake.cn, request: "GET /xxxxxxxx/xxxxxx.php?city_id=1&act=actShop&do=classimg&apply=WECHAT HTTP/1.1", host: "m.wdmcake.cn", referrer: "https://servicewechat.com/wxa6d966b9229b3123/117/page-frame.html"
2022/04/01 11:40:36 [warn] 47023#0: *673946 using uninitialized "path_info" variable, client: 1.202.223.235, server: m.wdmcake.cn, request: "GET /xxxxxxxx/xxxxxx.php?city_id=1&act=takeout&do=address&apply=WECHAT HTTP/1.1", host: "m.wdmcake.cn", referrer: "https://servicewechat.com/wxa6d966b9229b3123/117/page-frame.html"
分析后发现是nginx的vhost的server的pathinfo配置问题,这个配置在nginx老版本是没有,新版本就报错了,后来折腾了一下,处理好了,主要原因是nginx配置里定义了
$path_info 变量没有进行初始化的原因造成的
原来的老配置如下:
location ~ .*\.(php|php5) {
include fastcgi_params;
fastcgi_pass unix:/dev/shm/php-fcgi.sock;
fastcgi_index index.php;
fastcgi_read_timeout 800;
set $real_script_name $fastcgi_script_name;
if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
set $real_script_name $1;
set $path_info $2;
}
fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
}
后来改成:
location ~ .*\.(php|php5) {
include fastcgi_params;
fastcgi_pass unix:/dev/shm/php-fcgi.sock;
fastcgi_index index.php;
fastcgi_read_timeout 800;
set $real_script_name $fastcgi_script_name;
set $path_info "";
if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
set $real_script_name $1;
set $path_info $2;
}
fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
}
就可以了,主要加了一行代码:
set $path_info "";
用于初始化 $path_info变量