hello everyone.

not sure why but i get a 502 gateway nginx 1.10 error when i go to my ip. i just uploaded my files to home/django/django_project. i am guessing the problem is from gunicorn because nothing happens when i type the command service gunicorn restart via putty in the commandline

here is my nginx file

[error] 26244#26244: *674 connect() to unix:/home/django/gunicorn.socket failed (111: Connection refused) while connecting to upstream, client: 110.170.170.250, server: _, request: “HEAD http://67.207.87.22:80/PMA2014/ HTTP/1.1”, upstream: “http://unix:/home/django/gunicorn.socket:/PMA2014/”, host: “67.207.87.22”
2017/07/20 12:03:57 [error] 26244#26244: *674 connect() to unix:/home/django/gunicorn.socket failed (111: Connection refused) while connecting to upstream, client: 110.170.170.250, server: _, request: “HEAD http://67.207.87.22:80/PMA2015/ HTTP/1.1”, upstream: “http://unix:/home/django/gunicorn.socket:/PMA2015/”, host: “67.207.87.22”
2017/07/20 12:03:57 [error] 26244#26244: *674 connect() to unix:/home/django/gunicorn.socket failed (111: Connection refused) while connecting to upstream, client: 110.170.170.250, server: _, request: “HEAD http://67.207.87.22:80/PMA2016/ HTTP/1.1”, upstream: “http://unix:/home/django/gunicorn.socket:/PMA2016/”, host: “67.207.87.22”
2017/07/20 12:03:57 [error] 26244#26244: *674 connect() to unix:/home/django/gunicorn.socket failed (111: Connection refused) while connecting to upstream, client: 110.170.170.250, server: _, request: “HEAD http://67.207.87.22:80/PMA2017/ HTTP/1.1”, upstream: “http://unix:/home/django/gunicorn.socket:/PMA2017/”, host: “67.207.87.22”
2017/07/20 12:03:58 [error] 26244#26244: *674 connect() to unix:/home/django/gunicorn.socket failed (111: Connection refused) while connecting to upstream, client:

Would appreciate it if someone could point me to the right direction.
Thanks

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.

×
2 answers

Hi @iknwosu3

Correct, the problem is somewhere in Gunicorn, so we’re not going to get much from Nginx.
Make sure you’ve activated error logging:
http://docs.gunicorn.org/en/stable/settings.html#errorlog
Depending on your installation, sometimes it’s already enabled and you’ll find the log somewhere in your app directory or /var/log/gunicorn.log

  • hey, thanks for your response

    i tried the command –error-logfile FILE, –log-file FILE on putty but get “command not found”. any other idea what i could do?? thanks

    • @iknwosu3

      It’s not a command, it’s a parameter to add onto your Gunicorn command or you could define errorlog in your gunicorn.conf.py like this:

      errorlog = '/var/log/gunicorn-error.log'
      
      • I appreciate your patience. I cant seem to find the gunicorn.conf.py file. i think my gunicorn configuration is not properly set up. please could you give me an outline on how to put it in order?? because i know running the command service gunicorn restart on putty is supposed to output
        gunicorn stop/waiting
        gunicorn start/running, process 1505
        but instead..nothing happens.

        thanks

        • Try running this command and let’s see if it gives any hints:

          sudo journalctl -u gunicorn
          

          Otherwise I would redirect you to this tutorial:
          https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-16-04

          by Justin Ellingwood
          Django is a powerful web framework that can help you get your Python application or website off the ground. Django includes a simplified development server for testing your code locally, but for anything even slightly production related, a more secure and powerful web server...
          • hey. I followed the tutorial and its nothing short of amazing connecting the dots. I ran the command sudo systemctl status gunicorn
            and got this result. I am thinking this is the root of my problem. could you be of any assistance? here is what i got

            ● gunicorn.service - Gunicorn daemon for Django Project
            Loaded: loaded (/etc/systemd/system/gunicorn.service; enabled; vendor preset:
            Active: inactive (dead) (Result: exit-code) since Thu 2017-07-20 22:21:38 UTC
            Process: 11830 ExecStart=/usr/bin/gunicorn –name=django_project –pythonpath=
            Main PID: 11830 (code=exited, status=1/FAILURE)

            Jul 20 22:21:38 stylplus systemd[1]: gunicorn.service: Unit entered failed state
            Jul 20 22:21:38 stylplus systemd[1]: gunicorn.service: Failed with result ‘exit-
            Jul 20 22:21:38 stylplus systemd[1]: gunicorn.service: Service hold-off time ove
            Jul 20 22:21:38 stylplus systemd[1]: Stopped Gunicorn daemon for Django Project.
            Jul 20 22:21:38 stylplus systemd[1]: gunicorn.service: Start request repeated to
            Jul 20 22:21:38 stylplus systemd[1]: Failed to start Gunicorn daemon for Django

            it failed to start gunicorn.

  • plus i checked /var/log/ and did not see a gunicorn.log file

@iknwosu3

What’s the value of ExecStart in /etc/systemd/system/gunicorn.service?

  • it is
    [Service]
    WorkingDirectory=/home/django/djangoproject
    ExecStart=/usr/bin/gunicorn –name=django
    project –pythonpath=/home/django/djangoproject –bind unix:/home/django/gunicorn.socket –config /etc/gunicorn.d/gunicorn.py djangoproject.wsgi:application

    • @iknwosu3
      If you run this command, do you get any errors either in the console or in the error log file /home/django/error.log ?

      /usr/bin/gunicorn --name=django_project --pythonpath=/home/django/django_project --bind unix:/home/django/gunicorn.socket --config /etc/gunicorn.d/gunicorn.py --error-log /home/django/error.log django_project.wsgi:application
      

      Please use the </> button in the comment editor to preserve the formatting.

      • here is what i got after running the command
        Traceback (most recent call last):

         File "/usr/bin/gunicorn", line 9, in <module>
            load_entry_point('gunicorn==19.4.5', 'console_scripts', 'gunicorn')()
          File "/usr/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 74, in run
            WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
          File "/usr/lib/python2.7/dist-packages/gunicorn/app/base.py", line 192, in run
            super(Application, self).run()
          File "/usr/lib/python2.7/dist-packages/gunicorn/app/base.py", line 72, in run
            Arbiter(self).run()
          File "/usr/lib/python2.7/dist-packages/gunicorn/arbiter.py", line 206, in run
            self.halt(reason=inst.reason, exit_status=inst.exit_status)
          File "/usr/lib/python2.7/dist-packages/gunicorn/arbiter.py", line 302, in halt
            self.stop()
          File "/usr/lib/python2.7/dist-packages/gunicorn/arbiter.py", line 347, in stop
            time.sleep(0.1)
          File "/usr/lib/python2.7/dist-packages/gunicorn/arbiter.py", line 219, in handle_chld
            self.reap_workers()
          File "/usr/lib/python2.7/dist-packages/gunicorn/arbiter.py", line 464, in reap_workers
            raise HaltServer(reason, self.WORKER_BOOT_ERROR)
        gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
        root@stylplus:/#
        
        code
        
  • when i type
    root@stylplus:/# sudo journalctl -u gunicorn, i get this
    – Logs begin at Thu 2017-07-20 14:44:03 UTC, end at Thu 2017-07-20 23:05:32 UTC
    Jul 20 15:29:35 stylplus systemd[1]: Stopped Gunicorn daemon for Django Project.
    Jul 20 15:29:35 stylplus systemd[1]: Started Gunicorn daemon for Django Project.
    Jul 20 15:29:35 stylplus gunicorn[7487]: [2017-07-20 15:29:35 +0000] [7487] [INF
    Jul 20 15:29:35 stylplus gunicorn[7487]: [2017-07-20 15:29:35 +0000] [7487] [INF
    Jul 20 15:29:35 stylplus gunicorn[7487]: [2017-07-20 15:29:35 +0000] [7487] [INF
    Jul 20 15:29:35 stylplus gunicorn[7487]: [2017-07-20 15:29:35 +0000] [7495] [INF
    Jul 20 15:29:35 stylplus gunicorn[7487]: [2017-07-20 15:29:35 +0000] [7496] [INF
    Jul 20 15:29:35 stylplus gunicorn[7487]: [2017-07-20 15:29:35 +0000] [7499] [INF
    Jul 20 15:29:35 stylplus gunicorn[7487]: [2017-07-20 15:29:35 +0000] [7500] [INF
    Jul 20 15:29:35 stylplus gunicorn[7487]: [2017-07-20 15:29:35 +0000] [7501] [INF
    Jul 20 15:29:36 stylplus gunicorn[7487]: [2017-07-20 15:29:36 +0000] [7495] [ERR
    Jul 20 15:29:36 stylplus gunicorn[7487]: Traceback (most recent call last):
    Jul 20 15:29:36 stylplus gunicorn[7487]: File “/usr/lib/python2.7/dist-package
    Jul 20 15:29:36 stylplus gunicorn[7487]: worker.initprocess()
    Jul 20 15:29:36 stylplus gunicorn[7487]: File ”/usr/lib/python2.7/dist-package
    Jul 20 15:29:36 stylplus gunicorn[7487]: super(GeventWorker, self).init
    proc
    Jul 20 15:29:36 stylplus gunicorn[7487]: File “/usr/lib/python2.7/dist-package
    Jul 20 15:29:36 stylplus gunicorn[7487]: self.load_wsgi()
    Jul 20 15:29:36 stylplus gunicorn[7487]: File ”/usr/lib/python2.7/dist-package
    Jul 20 15:29:36 stylplus gunicorn[7487]: self.wsgi = self.app.wsgi()
    Jul 20 15:29:36 stylplus gunicorn[7487]: File “/usr/lib/python2.7/dist-package
    Jul 20 15:29:36 stylplus gunicorn[7487]: self.callable = self.load()
    lines 1-23

Submit an Answer