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

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

訪問目錄發現報502錯誤nginx

百度了不少方法 都無論用  我擦 各類抓狂-----vim

本來Nginx配置以下:centos

網上找了不少方法:服務器

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

顯示 : 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"php-fpm

發現是fastcgi_pass路徑的問題致使,測試

借鑑如下解決方法spa

解決方法一:unix

# 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;

就此  訪問解析成功

相關文章
相關標籤/搜索