封绝的世界

nginx 502 bad gateway

嗯哼,刚装了个ubuntu的lnmpnginx -t 和 serive nginx start 没有问题。但装完的时候访问显示502。网站配置文件如下:

server {
listen
80; ## listen for ipv4 #listen [::]:80 default_server ipv6only=on; ## listen for ipv6 server_name *.webossgoo.com; root /var/www/html/bossgoo-src/; index index.php; location / { add_header 'Access-Control-Allow-Origin' '*'; try_files $uri $uri/ /index.php$is_args$args; } location ~ ^/assets/.*\.php$ { deny all; } location ~ \.php$ { include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #fastcgi_pass 127.0.0.1:9000; fastcgi_pass unix:/run/php/php5.6-fpm.sock; try_files $uri =404; } location ~* /\. { deny all; } error_log logs/error_www.webossgoo.com.log error; }

也不知道什么问题,就去看了一下nginx日志  /usr/share/nginx/logs/error_www.webossgoo.com.log,发现了这个错误

日志有点多如何清空呢echo '' > /usr/share/nginx/logs/error_www.webossgoo.com.log

2021/07/19 15:22:32 [crit] 31366#31366: *16 connect() to unix:/var/run/php /php5.6-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 127.0.0.1, server: *.webossgoo.com, request: "GET / HTT P/1.1", upstream: "fastcgi://unix:/var/run/php/php5.6-fpm.sock:", host: "www.webossgoo.com"

2021/07/19 15:25:14 [error] 32074#32074: *1 connect() failed (111: Connect ion refused) while connecting to upstream, client: 127.0.0.1, server: *.we bossgoo.com, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.webossgoo.com"


去搜了一下,这样的错误有两个解决方式


执行如下命令查看是否启动了php-fpm,如果没有则启动你的php-fpm即可

netstat -ant | grep 9000

cat /etc/php/5.6/fpm/php-fpm.conf

include=/etc/php/5.6/fpm/pool.d/*.conf

cat /etc/php/5.6/fpm/pool.d/www.conf
listen = /run/php/php5.6-fpm.sock

因为Nginx和PHP-FPM的进程间通信有两种方式,一种是TCP,一种是UNIX Domain Socket.
其中TCP是IP加端口,可以跨服务器.而UNIX Domain Socket不经过网络,只能用于Nginx跟PHP-FPM都在同一服务器的场景.用哪种取决于你的PHP-FPM配置:
方式1:
php-fpm.conf: listen = 127.0.0.1:9000
nginx.conf: fastcgi_pass 127.0.0.1:9000;
方式2:
php-fpm.conf: listen = /tmp/php-fpm.sock
nginx.conf: fastcgi_pass unix:/run/php/php5.6-fpm.sock;
其中php-fpm.sock是一个文件,由php-fpm生成,类型是srw-rw----. 

这个具体怎么用要去php fpm里面去看他的配置文件
/etc/php/5.6/fpm/pool.d/www.conf里面的Listen

如果Listen是端口就写127.0.0.1:9000;

如果是路径,nginx的配置文件也要写路径,unix:/run/php/php5.6-fpm.sock;

nginx -t 和 serive nginx restart

重新访问就好了

posted @ 2021-07-19 16:11  天边的云云  阅读(149)  评论(0编辑  收藏  举报