首页 > 编程知识 正文

502报错是怎么解决,502

时间:2023-05-03 09:18:32 阅读:276550 作者:1957

## 把111.conf改为test.conf(因为之前的网站是www.test.com)

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

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

[root@localhost vhosts]# vim test.conf

server {

   listen 80;

   server_name www.test.com;

   index index.html index.htm index.php;

   root /data/www;

   location ~ .php$ {

       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;

   }

}

## 检查语法并重新加载

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

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

## 浏览器访问

## 出现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

解释说明:

添加关于监听的一个用户和组的人指定一下,既然我们nobody想去读它,那我们就指定nobody 。

## 检查语法并重启服务

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

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

  

## 再刷新网页可以访问了 

参考资料:

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


转载于:https://blog.51cto.com/warm51fun/1888103

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。