David Foie Gras
David Foie Gras

Reputation: 2070

How to solve this error Nginx and uwsgi 502 bad gateway

I faced 502 BadGateway error. How to solve this?

I catched nginx access log and error log

access log

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"

error log

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 config file

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 config file

[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

I using django, and nginx's configtest says OK, not fail.

I'm even as root user, this error occurred always.

nginx/1.4.6// Ubuntu 14//

and pip3 freeze to version

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

How can i solve it ?

Would you help me?

edit

In tmp/*.sock

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

Upvotes: 0

Views: 2349

Answers (1)

Import this
Import this

Reputation: 26

run uswgi file using command:

uwsgi --ini mysite_uwsgi.ini

Upvotes: 1

Related Questions