一:错误场景:leyangjun-cc-web.com/api/cc/callback.php 访问返回502
二:Nginx错误报错为:
2018/10/22 18:07:09 [crit] 775#0: *41 connect() to unix:/var/run/php7.0-fpm.sock failed
三:错误原因
我的Nginx配置文件,配置的不对
server {
listen 80;
server_name leyangjun-cc-web.com;
root /www/leyanjgun/cc/src/App/; index index.html index.htm index.php;
access_log /www/log/dev-cc.leyangjun.com-access.log;
error_log /www/log/dev-cc.leyangjun.com-error.log error; location / {
try_files $uri $uri/ /index.php?$query_string;
} location ~ \.php$ {
fastcgi_pass unix:/run/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
#include /usr/local/etc/nginx/php-fpm;
include fastcgi_params;
} error_page 404 403 500 502 503 504 /error.html;
location = /error.html {
root /Users/leyangjun/code/;
}
}
就是因为 fastcgi_pass unix:/run/php7.0-fpm.sock; 这个配置,Nginx走的是sock配置,但是我php的www.conf配置文件中没有对sock文件监听,导致Nginx报错
解决方法:
一:vi /usr/local/etc/php/7.1/php-fpm.d/www.conf 增加对文件的监听,能后保存重启服务即可
二:或者直接改用IP形式使用
server {
listen 80;
server_name leyangjun-cc-web.com;
root /www/leyanjgun/cc/src/App/; index index.html index.htm index.php;
access_log /www/log/dev-cc.leyangjun.com-access.log;
error_log /www/log/dev-cc.leyangjun.com-error.log error; location ~ ^/(page|aj|api|test)/{
try_files $uri $uri/ /index.php?$query_string;
} location / {
try_files /index.html =404;
} location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param MY_ENV 'develop';
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}}
保存重启Nginx服务即可