如何解决这个错误Nginx和uwsgi 502坏网关

时间:2016-09-27 16:37:15

标签: django nginx uwsgi

我遇到了502 BadGateway错误。怎么解决这个问题?

我抓住了nginx访问日志和错误日志

访问日志

120.142.184.164 - - [27/Sep/2016:16:15:48 +0000] "GET / HTTP/1.1" 502 583 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36"

错误日志

2016/09/27 16:15:48 [crit] 3585#0: *1 connect() to unix:/tmp/PROJECT_NAME.sock failed (13: Permission denied) while connecting to upstream, client: 120.142.184.164, server: 52.78.105.246, request: "GET / HTTP/1.1", upstream: "uwsgi://unix:/tmp/PROJECT_NAME.sock:", host: "52.78.105.246:8000"

nginx配置文件

server {

    listen 8000;
    server_name 52.78.105.246;
    access_log /var/log/nginx/example_access.log;
    error_log /var/log/nginx/example_error.log;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /home/ghdalsrn/PROJECT_NAME;
    }

    location / {
        include         uwsgi_params;
        uwsgi_pass      unix:/tmp/PROJECT_NAME.sock;
  }
}

uwsgi配置文件

[uwsgi]
vhost=true
project = PROJECT_NAME
base = /home/ghdalsrn
plugin = python

chdir = %(base)/%(project)
home = %(base)/.virtualenvs/ENV_NAME
module = %(project).wsgi:application

enable-threads = true
master = true
processes = 5

socket = /tmp/%(project).sock
chmod-socket=666


vacuum = true

我使用django,而nginx的configtest说好,不会失败。

我甚至是root用户,这个错误总是发生。

nginx / 1.4.6 // Ubuntu 14 //

和pip3冻结到版本

chardet==2.2.1
colorama==0.2.5
command-not-found==0.3
html5lib==0.999
language-selector==0.1
pbr==1.10.0
pycurl==7.19.3
pygobject==3.12.0
python-apt==0.9.3.5ubuntu2
requests==2.2.1
six==1.10.0
stevedore==1.17.1
uWSGI==2.0.13.1
ufw==0.34-rc-0ubuntu2
unattended-upgrades==0.1
urllib3==1.7.1
virtualenv==15.0.3
virtualenv-clone==0.2.6
virtualenvwrapper==4.7.2
wheel==0.24.0

我该如何解决?

你会帮我吗?

修改

在tmp / *。袜子

srw-rw-r-- 1 root     www-data 0 Sep 27 14:17 /tmp/PROJECT_NAME.sock
srwxrwxr-x 1 ghdalsrn ghdalsrn 0 Sep 27 16:59 /tmp/uwsgi.sock

1 个答案:

答案 0 :(得分:1)

使用命令运行uswgi文件:

uwsgi --ini mysite_uwsgi .ini