Report this

What is the reason for this report?

The dreaded 502 error

Posted on March 1, 2017

I use Pycharm while creating a website using Django/python. The website works as expected on localhost through Pycharm, so I decided to try and move it to a webserver. I followed this tutorial multiple times but still get the 502 error. https://www.youtube.com/watch?v=Y-CT_l1dnVU&t=609s

Ngnix error reads:

2017/03/01 04:53:33 [error] 2232#2232: *48 connect() to unix:/home/django/gunicorn.socket failed (111: Connection refused) while connecting to upstream, client: *client IP*, server: _, request: "GET / HTTP/1.1", upstream: "http://unix:/home/django/gunicorn.socket:/", host: "*host IP*"

and Gunicorn error reads:

root@ueba:/home/django/django_project# service gunicorn status
● gunicorn.service - Gunicorn daemon for Django Project
   Loaded: loaded (/etc/systemd/system/gunicorn.service; enabled; vendor preset:
   Active: inactive (dead) (Result: exit-code) since Wed 2017-03-01 04:42:29 UTC
  Process: 23288 ExecStart=/usr/bin/gunicorn --name=django_project --pythonpath=
 Main PID: 23288 (code=exited, status=1/FAILURE)

Mar 01 04:42:29 ueba systemd[1]: gunicorn.service: Unit entered failed state.
Mar 01 04:42:29 ueba systemd[1]: gunicorn.service: Failed with result 'exit-code
Mar 01 04:42:29 ueba systemd[1]: gunicorn.service: Service hold-off time over, s
Mar 01 04:42:29 ueba systemd[1]: Stopped Gunicorn daemon for Django Project.
Mar 01 04:42:29 ueba systemd[1]: gunicorn.service: Start request repeated too qu
Mar 01 04:42:29 ueba systemd[1]: Failed to start Gunicorn daemon for Django Proj
lines 1-12/12 (END)

if it matters, the file system is:

*home
   *Django
      *Django_project
          *Django_project
             *wsgi.py
             *init.py
             *settings.py
             *urls.py
          *ueba
             *migrations (folder)
             *static (folder)
             *templates (folder)
             *init.py
             *admin.py
             *apps.py
             *tests.py
             *views.py
             *models.py

I feel like I’ve tried multiple suggestions and variations of configs for both the ngnix and gunicorn through docs on OD but still haven’t nailed it out.

Let me know if I need to provide more docs, thanks!



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

You only have to look at your Django project (or Gunicorn more specifically). This has nothing to do with Nginx, right now at least, since you can’t even run Gunicorn. Try starting it with debug level, in hope to get a better error message than “exit-code”: gunicorn_django -b 127.0.0.1:8000 --settings=myapp.settings.dev --debug --log-level debug Modify the command, so it fits your project, just leave the --debug --log-level debug

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.