nginx配置文件: Nginx 默认使用 include enable-php.conf; 通过enable-php.conf 来解析PHP,该文件内容如下 location ~ [^/]\.php(/|$){try_files $uri =404;fastcgi_pass unix:/tmp/php-cgi.sock;fastcgi_in...
nginx配置文件:
Nginx 默认使用 include enable-php.conf; 通过enable-php.conf 来解析PHP,该文件内容如下
location ~ [^/]\.php(/|$)
{
try_files $uri =404;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
而我们使用nginx自然要使用fastCGI来跑PHP,Nginx之所以并发高跟fastCGI脱不开关系,有自动管理php-cgi进程的能力,总之就是它很屌,使用Nginx不用fastCGI的话就好像抽烟不点火。
因此我们看到 Nginx的配置文件中有 :include enable-php.conf; 这行代码的话,请自觉在前面加个#注释掉~
然后添加一个类似的location,下面是例子
location ~ [^/]\.php(/|$)
{
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
# fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include /usr/local/nginx/conf/fastcgi.conf;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; #该参数正常情况下应打开,如果报错access deny 且常规方法无法解决时 请注释掉
include /usr/local/nginx/conf/fastcgi_params;
}
然后别急着重启Nginx,
vim /usr/local/php/etc/php-fpm.conf //修改此文件
进来后,修改listen, 对应Nginx中的 9000端口
#listen = /tmp/php-cgi.sock listen = 127.0.0.1:9000
然后重启php-fpm 和 nginx, service不行的用systemctl命令。
service php-fpm restart service nginx restart
OK。
结束
本文标题为:在nginx上用FastCGI解析PHP
基础教程推荐
- 解析PHP中Exception异常机制 2023-06-13
- PHP设计模式之状态模式定义与用法详解 2022-10-12
- PHP中的输出缓冲控制详解 2023-06-03
- 在laravel中实现事务回滚的方法 2023-02-22
- php fread函数使用方法总结 2023-01-19
- PHP5.0 TIDY_PARSE_FILE缓冲区溢出漏洞的解决方案 2022-11-26
- php+mysql+ajax 局部刷新点赞/取消点赞功能(每个账号只点赞一次) 2023-04-24
- PHP如何将头像图片转换圆形图片 2023-08-30
- CentOS 7 编译安装PHP7 2023-09-02
- PHP树形结构tree类用法示例 2022-12-15
