安裝好nginx,php環境後,配置虛擬主機,結果訪問後就報502 gateway,查看日誌文件後,顯示錯誤以下:php
2019/04/29 16:24:39 [error] 19433#19433: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.1.52, server: 192.168.1.222, request: "GET / HTTP/1.1"
解決方案,先查看下php-fpm是否啓動,而後查看虛擬主機配置中的 root 配置html
server { listen 80; server_name 192.168.1.222; charset utf-8; location / { root /data/wwwroot; index index.php index.html index.htm; } location ~ \.php$ { #注意這裏root配置與當前server下的root保持一致 #個人報錯緣由是我把root這項給刪除 root /data/wwwroot; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
而後重啓下nginx就能夠訪問了。nginx