問題
win10下安裝wsl子系統,併成功搭建lnmp環境後,ngixn請求出現502錯誤。查看nginx日誌(/var/log/nginx/error.log)報錯如下。
2020/06/16 11:09:50 [error] 2293#2293: *1 upstream timed out (110: Connection timed out) while reading upstream, client: 192.168.58.102, server: 192.168.xx.xx, request: "POST 你的請求地址 HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.2-fpm.sock:", host: "192.168.xx.xx", referrer: "你的請求地址"
定位排查
檢查php-fpm是否運行
執行命令查看php-fpm的啓動狀態,如果沒有啓動則啓動php-fpm即可
/etc/init.d/php7.2-fpm status
或
ps -ef|grep php
php-fpm隊列是否滿了
1.在nginx配置中加一個location,設置如下
location ~ ^/status$ {
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
}
2.在php-fpm.conf中打開選項
pm.status_path = /status
3.設置完成後即可通過 http://域名/status 看到當前的php情況。示例如下。
確認nginx配置文件
因為nginx和php有兩種連接方法。
連接方式一:
fastcgi_pass 127.0.0.1:9000;
連接方式二:
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
這個具體怎麼用要去php-fpm裏面去看他的配置文件
/etc/php/7.2/fpm/pool.d/www.conf裏面的Listen配置。
如果Listen是端口就寫127.0.0.1:9000;
如果是路徑,nginx的配置文件也要是路徑,unix:/run/php/php7.0-fpm.sock;
確認兩個地址配置一直後,重啓一下nginx就可以訪問了。