天天看點

Nginx 13: Permission denied 解決方案

本文首發于我的個人部落格: 尾尾部落

今天在用uwsgi+nginx在部署flask應用時,遇到502的錯誤,

vim /var/log/nginx/error.log

檢視nginx的錯誤日志,提示如下錯誤資訊:

2018/07/22 00:46:36 [crit] 15890#15890: *74 connect() to unix:/root/jianshuvue/jianshu.sock failed (13: Permission denied) while connecting to upstream, client: 120.42.13.98, server: jianshu.weiweiblog.cn, request: "GET /favicon.ico HTTP/1.1", upstream: "uwsgi://unix:/root/jianshuvue/jianshu.sock:", host: "jianshu.weiweiblog.cn", referrer: "http://jianshu.weiweiblog.cn/jianshu/67eb7ed414d3"
           

Permission denied,一看就知道是權限出了問題,通過

ps -ef | grep nginx

,檢視nginx的程序資訊:

root     15889     1  0 00:01 ?        00:00:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
www-data 15890 15889  0 00:01 ?        00:00:00 nginx: worker process
root     16795 15654  0 00:48 pts/3    00:00:00 grep --color=auto nginx
           

發現nginx程序的使用者是nginx,而我們建立/root/jianshuvue/jianshu.sock檔案的使用者是root,是以,隻要把nginx的程序user改為root即可,

vim /etc/nginx/nginx.conf

:

1 # user www-data;
  2 user root;
  3 worker_processes auto;
  4 pid /run/nginx.pid;
           

之後,

/etc/init.d/nginx restart

重新開機nginx,就可以正常通路網站了。

繼續閱讀