问题背景
配置nginx+php服务的时候,发现网站能打开html,打开php文件就显示502,一般这个是php没启动啊啥的导致不能正常解析php文件。
原因分析
因为nginx解析php文件是交给fastcgi_pass 来处理的,默认一般fastcgi_pass 有两种方式来解析php,一种是常见的tcp也就是监听9000端口,这边只做tcp的解析。
netstat -ntlp 查看9000端口是没有监听的,默认不再监听9000 端口了,监听的是/tmp/php-cgi-56.sock
[root@localhost pazzn]# netstat -ntlp ###没有9000端口监听
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 13031/nginx: master
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1425/sshd
tcp 0 0 0.0.0.0:888 0.0.0.0:* LISTEN 13031/nginx: master
tcp 0 0 0.0.0.0:8888 0.0.0.0:* LISTEN 3818/python
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 3467/master
tcp6 0 0 :::22 :::* LISTEN 1425/sshd
tcp6 0 0 ::1:25 :::* LISTEN 3467/master
tcp6 0 0 :::3306 :::* LISTEN 3401/mysqld
解决方案
1.找到/php.conf
[root@localhost ~]# find / -name php-fpm.conf
/www/server/php/56/etc/php-fpm.conf [root@localhost ~]#vi /www/server/php/56/etc/php-fpm.conf
2.用; 注释掉sock监听的方式,增加9000端口监听
[global]
pid = /www/server/php/56/var/run/php-fpm.pid
error_log = /www/server/php/56/var/log/php-fpm.log
log_level = notice
[www]
#listen = /tmp/php-cgi-56.sock
listen = 9000
listen.backlog = -1
listen.allowed_clients = 127.0.0.1
listen.owner = www
listen.group = www
listen.mode = 0666
user = www
group = www
pm = dynamic
pm.status_path = /phpfpm_56_status
pm.max_children = 80
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 20
request_terminate_timeout = 100
request_slowlog_timeout = 30
slowlog = var/log/slow.log
3.重启php,完美打开解析php文件
[root@localhost ]# systemctl restart php-fpm-56.service
注意:一定要先保证nginx.conf的配置文件是正确的哦。
参考链接:https://blog.csdn.net/moshowgame/article/details/84135977
|