常見的502問題解決

## 把111.conf改成test.conf(由於以前的網站是www.test.com)php

[root@localhost vhosts]# cd /usr/local/nginx/conf/vhosts/html

[root@localhost vhosts]# mv 111.conf test.conflinux

[root@localhost vhosts]# vim test.confnginx

server {vim

   listen 80;瀏覽器

   server_name www.test.com;ide

   index index.html index.htm index.php;php-fpm

   root /data/www;網站

   location ~ \.php$ {spa

       include fastcgi_params;

       fastcgi_pass  unix:/tmp/www.sock;

     # fastcgi_pass  127.0.0.1:9000;

       fastcgi_index index.php;

       fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;

   }

}

WEBRESOURCE56ee75469ffe53672c464106a0c23

## 檢查語法並從新加載

[root@localhost vhosts]# /usr/local/nginx/sbin/nginx -t

[root@localhost vhosts]# /etc/init.d/nginx reload

## 瀏覽器訪問

WEBRESOURCE8f4c683425c4eee3c1ed638ed05e5

## 出現502錯誤,查看nginx日誌

[root@localhost vhosts]# cat /usr/local/nginx/logs/nginx_error.log

2016/10/24 22:03:33 [crit] 9683#0: *463 connect() to unix:/tmp/www.sock failed (13: Permission denied) while connecting to upstream, client: 106.37.236.187, server: www.test.com, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/tmp/www.sock:", host: "www.test.com"

解釋說明:

nginx的主配置文件(/usr/local/nginx/conf/nginx.conf)裏有說明nginx的日誌路徑在哪裏;

日誌裏說沒有權限去讀/tmp/www.sock

## 查看一下/tmp/www.sock權限

[root@aminglinux vhosts]# ls -l /tmp/www.sock

srw-rw---- 1 root root 0 Oct 23 23:37 /tmp/www.sock

解釋說明:

顯示的屬主和屬組是可讀寫的,惟獨其餘人沒有讀的權限;主和組全是root,而咱們要去讀這個sock文件的

用戶是誰呢?用ps aux|grep nginx查看是nobody;由於咱們在配置文件中指定了unix:sock在哪裏,咱們已經告訴了它去哪裏讀,因此它會502;沒有權限,讀不到就會502

## 查看nginx的用戶

[root@localhost vhosts]# ps aux|grep nginx

root       914  0.0  0.1  44744  1188 ?        Ss   Oct01   0:00 nginx: master process /www/server/nginx/sbin/nginx -c /www/server/nginx/conf/nginx.conf

www        915  0.0  2.2  65604 22552 ?        S    Oct01   0:00 nginx: worker process                                            

www        916  0.0  2.1  65556 22244 ?        S    Oct01   6:11 nginx: worker process                                            

nobody    9683  0.0  0.3  26252  3908 ?        S    22:01   0:00 nginx: worker process                                          

nobody    9684  0.0  0.3  26252  3636 ?        S    22:01   0:00 nginx: worker process   

解決辦法

## 編輯php配置文件

[root@localhost hosts]# vim /usr/local/php-fpm/etc/php-fpm.conf

WEBRESOURCE5ad55dac60e55a2b9b220d6aea3a8

解釋說明:

添加關於監聽的一個用戶和組的人指定一下,既然咱們nobody想去讀它,那咱們就指定nobody 。

## 檢查語法並重啓服務

[root@localhost vhosts]# /usr/local/php-fpm/sbin/php-fpm -t    

[root@localhost vhosts]# /etc/init.d/php-fpm restart     

  

## 再刷新網頁能夠訪問了 

WEBRESOURCEe378b20bc14e947fbdc0315a04e06

參考資料:

http://www.apelearn.com/bbs/thread-9109-1-1.html

相關文章
相關標籤/搜索