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实现生成数据字典功能示例 2022-10-18
- TP5(thinkPHP5框架)基于bootstrap实现的单图上传插件用法示例 2023-01-19
- laravel model模型定义实现开启自动管理时间created_at,updated_at 2023-03-02
- PHP使用SMTP邮件服务器发送邮件示例 2022-11-16
- thinkPHP3.2.2框架行为扩展及demo示例 2022-11-07
- PHP数据加密方式梳理介绍 2023-07-03
- TP5 连接多个数据库及使用方法 2023-08-30
- PHP实现创建一个RPC服务操作示例 2023-04-01
- PHP删除数组中指定值的元素常用方法实例分析【4种方法】 2022-11-12
- php中使用array_filter()函数过滤数组实例讲解 2023-05-19