nginx + php-fpm 开启 PATH_INFO 模式
很多框架默认路由都是 PATH_INFO 模式,比如默认在 Apache 并且没有 rewrite 时,CodeIgniter 一般可以这样访问 /index.php/controller/action ,那么 nginx 和 php-fpm 如何设置支持 PATH_INFO 模式呢?
php.ini 中一个与 PATH_INFO 有关的设置是 cgi.fix_path 默认为 1,我们将其设置为 0。
php.ini 设置:
1
|
cgi.fix_path = 0
|
接下来是 nginx 配置:
1
2
3
4
5
6
7
8
9
10
11
|
location ~ \.php($|/) {
# 下面这一行设置 $fastcgi_script_name 和 $fastcgi_path_info 的值,具体请看 nginx 文档
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# 下面这行也可以为 fastcgi_pass unix:/var/run/php-fpm.sock 看你的 fpm 设置了
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
# 下面这行不能少默认 fastcgi_params 里面并没有 SCRIPT_FILENAME
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
|
openeuler中默认写法:
1 2 3 4 5 6 7 8 9 10 11 12 | index index.php index.html index.htm; location ~ \.(php|phar)(/.*)?$ { fastcgi_split_path_info ^(.+\.(?:php|phar))(/.*)$; fastcgi_intercept_errors on ; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_pass php-fpm; } |
配置php-fpm模块
vim php-fpm.conf
1 2 3 | upstream php-fpm { server unix:/run/php-fpm/www.sock; } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
2019-09-26 LEDE安装zerotier 无法启动解决方法