debian/ubuntu运行php出现502错误

在debian/ubuntu上安装Nginx+php之后,之前文章中总结了本博主遇到的奇怪的php 404错误

更常见的是502错误。

那么排除了之前文章内提及的nginx和php进程权限不一致,需全部改为nginx以外,在尝试使用socks和127.0.0.1:9000代理模式均为502错误,查看日志是“php连接被拒绝”php-fpm连接被拒绝,那么则可能是nginx的站点conf文件有问题。

本人经过又一天的摸索总结,发现解决办法,就是/etc/nginx/conf.d/default.conf必须严格按照标准格式写

以下是最简洁的conf文件语句:

 server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
index index.php index.html index.htm;
#access_log /var/log/nginx/log/host.access.log main;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/run/php5-fpm.sock;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
#location ~ /\.ht {
# deny all;
#}
}

参考文献:
1、关于PHP-FPM的服务器进程和站点进程
2、php-fpm连接被拒绝,permission deny或refuse

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据