nginx 配置虛擬主機訪問PHP文件 502錯誤的解決方法


最近配置Nginx 服務器虛擬主機

訪問目錄發現報502錯誤

百度了很多方法 都不管用  我擦 各種抓狂-----

原本Nginx配置如下:

網上找了很多方法:

查看日志   借助nginx的錯誤日志來進行排查vim /usr/local/nginx/logs/nginx_error.log 

顯示 : connect() to unix:/tmp/php-fcgi.sock failed (13: Permission denied) while connecting to upstream, client: 127.0.0.1, server: localhost, request: "GET /2.php HTTP/1.1", upstream: "fastcgi://unix:/tmp/php-fcgi.sock:", host: "localhost"

發現是fastcgi_pass路徑的問題導致,

借鑒以下解決方法

解決方法一:

# ll /tmp

srw-rw---- 1 root  root     0 Feb 22 00:58 php-cgi.sock

修改后的權限

[root@centos  nginx]# chmod 777 /tmp/php-cgi.sock

[root@centos nginx]# ll /tmp

srwxrwxrwx 1 root  root     0 Feb 22 00:58 php-cgi.sock

修改權限后測試成功

重啟  service php-fpm restart  

       service nginx restart 

# ll /tmp

srw-rw---- 1 root  root     0 Feb 22 00:58 php-cgi.sock

權限又恢復了原樣

后修改  vim /etc/init.d/php-fpm    在start)  的fi  后加上 chmod 777 /tmp/php-cgi.sock

解決方法二:   

配置錯誤 因為 nginx 找不到php-fpm了,所以報錯,一般是fastcgi_pass后面的路徑配置錯誤了,后面可以是socket或者是ip:port

修改php-fpm的配置文件  vim /usr/local/php/etc/php-fpm.conf   里面的 listen = /tmp/php-fcgi.sock  改為  listen = 127.0.0.1:9000

修改nginx的配置文件   vim /usr/local/nginx/conf/nginx.conf     里面的 fastcgi_pass unix:/tmp/php-cgi.sock; 改為 fastcgi_pass 127.0.0.1:9000;

就此  訪問解析成功

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM