Ubuntu系统中Nginx怎么开启pathinfo模式?

技术文章 litterfat 5年前 (2018-12-14) 5534次浏览 已收录 扫描二维码

Ubuntu系统中 Nginx 怎么开启 pathinfo 模式?
可能有人要问为什么 apache 不会出现这个问题?
apache 一般是以模块的方式运行 php,apache 可以对$_SERVER[‘PATH_INFO’]的值进行设置,不需要另外配置。
新版本的 nginx 也可以使用fastcgi_split_path_info指令来设置PATH_INFO,旧的方式不再推荐使用,在location段添加如下配置。
location ~ .PHP下加入如可字段即可


#去掉$是为了不匹配行末,即可以匹配.php/,以实现 pathinfo
location ~ \.php
{
#原有代码

#定义变量 $path_info
set $path_info “”;
#定义变量 $real_script_name,用于存放真实地址
set $real_script_name $fastcgi_script_name;
#如果地址与引号内的正则表达式匹配
if ($fastcgi_script_name ~ “^(.+?\.php)(/.+)$”) {
#将文件地址赋值给变量 $real_script_name
set $real_script_name $1;
#将文件地址后的参数赋值给变量 $path_info
set $path_info $2;
}
#配置 fastcgi 的一些参数
fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
}


喜欢 (1)
Searching for the best XXX images on the web? Look no further than our premier destination for all things erotic. the highest quality content on the web, with crystal clear video and audio that will make you feel like you're right there in the action https://eroticpictures.org/