django - Gunicorn with unix socket not working gives 502 bad gateway -


i'm following http://www.obeythetestinggoat.com/book/chapter_08.html book, , says add unix socket run nginx server gunicorn, did. nginx file

server { listen 80; server_name mydjsuperlist-staging.tk;  location /static { alias /home/elspeth/sites/mydjsuperlist-staging.tk/static; }  location / { proxy_set_header host $host;     proxy_pass http://unix:/tmp/mydjsuperlist-staging.tk.socket; } }  

nginx reloads without failure , checked nginx -t

when run:

gunicorn --bind unix:/tmp/mydjsuperlist-staging.tk.socket superlists.wsgi:application 

it succesfully creates mydjsuperlist-staging.tk.socket file in tmp folder , on terminal

2016-09-01 18:56:01 [15449] [info] starting gunicorn 18.0 2016-09-01 18:56:01 [15449] [info] listening at: unix:/tmp/mydjsuperlist-staging.tk.socket (15449) 2016-09-01 18:56:01 [15449] [info] using worker: sync 2016-09-01 18:56:01 [15452] [info] booting worker pid: 15452 

everything seems fine, when go site mydjsuperlist-staging.tk gives (502) bad gateway error. when using port site running perfectly. doing wrong on here ?

i got same problem, , doing same tutorial too, here solution following this: http://docs.gunicorn.org/en/stable/deploy.html

note: not using upstart instead, using systemd service

1) make service in /etc/systemd/system/nginx.service

[unit] description=gunicorn server {sitename} after=network.target  [service] user={user} group=www-data workingdirectory=/home/{user}/sites/{sitename}/source execstart=/home/{user}/sites/{sitename}/virtualenv/bin/gunicorn --workers 3 --bind unix:/tmp/{sitename}.socket superlists.wsgi:application restart=always  [install] wantedby=multi-user.target 

2) followed next steps http://docs.gunicorn.org/en/stable/deploy.html making gunicorn.socket , gunicorn.conf, notice socket status inactive, think not necessary.

the gunicorn.conf file in /usr/lib/tmpfiles.d/gunicorn.conf

d /run/gunicorn 0755 someuser someuser - 

next enable services autostart @ boot:

$ systemctl enable nginx.service $ systemctl enable gunicorn.socket

either reboot, or start services manually:

$ systemctl start nginx.service $ systemctl start gunicorn.socket

some hints help:

  • make sure service , running

    $ systemctl status gunicorn.service

  • check if nginx configuration ok

    $ sudo nginx -t

  • check letter misplaced
  • make sure put domain in allowed_hosts string, took 1 hour realize miss ' '

allowed_hosts = [**'**{sitename}**'**]

it took me 6 hours running first time doing , 0 knowledge in unix think ok.

hope helps, keep trying until works !!


Comments