I am getting failed (111: Connection refused) while connecting to upstream error in my nginx error log file while trying to access the Django app on my droplet. I understand that the issue my be that nginx is not finding gunicorn. I tried to start gunicorn but getting “start: Unknown job: gunicorn” error, I even tried restarting the droplet but still getting the gunicorn “unknown gunicorn”.

There is also nothing getting printed in my gunicon.log file. I also tried the solutions on similar posts on DO but nothing works

Any help will be highly appreciated, been having this issue for two days with no clue

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.

×
3 answers

@hansen I managed to find the solution, it seems like it was timing out, I set –timeout parameter to 120 and it works now. Thank you once again for all the insights provided.

It led to the solution.

When launching Gunicorn, try adding the parameter --log-level debug which should add debug to log. Make sure you haven’t change the path to the log file to somewhere else in gunicorn.conf

  • you mean like “sudo service gunicorn –log-level start”. if you can give me the syntax of the command @hansen

    • @kamstan6 No, the problem is with Gunicorn (or your project), so we need to start it by itself:
      gunicorn --bind unix:/path/to/myproject/myproject.sock myproject.wsgi:application --log-level debug
      If you use your IP to bind to, then you can use that.

      • I am still not getting anything in my gunicorn.log file here is my gunicorn.conf and nginx.conf for more clarity

        gunicorn.conf

        description "Gunicon application server handling tecjavenue 137 website"
        
        start on runlevel [2345]
        stop on runlevel [!2345]
        
        respawn
        setuid arnold
        setgid www-data
        chdir /home/arnold/beta_test/ta_137_deplopy/project
        
        exec /home/arnold/beta_test/myenv/bin/gunicorn --workers 3 --bind 127.0.0.1:8000 techAvenue.wsgi:application --access-logfile  /var/log/upstart/gunicorn.log --log-level debug
        ~                                                                                                                                                                             
        

        nginx.conf

        server {
            listen 80;
            server_name 188.166.58.113;
            error_log /var/log/nginx/ta_137.log;
            access_log /var/log/nginx/ta_137_access.log;
        
            location = /favicon.ico { access_log off; log_not_found off; }
            location /static/ {
                root /home/arnold/beta_test/ta_137_deplopy/project;
            }
        
            location / {
                include proxy_params;
                proxy_pass http://127.0.0.1:8000;
            }
        }
        
        

        But I am still getting the 111: connection refused and my gunicorn.log file has no logs in it.

        Thank you again for your support

        • This is not a problem with Nginx, since your Gunicorn can’t start, then Nginx of course cannot connect to it.

          Try executing this, that should give you the error log instead of access log:

          /home/arnold/beta_test/myenv/bin/gunicorn --workers 3 --bind 127.0.0.1:8000 techAvenue.wsgi:application --error-logfile /var/log/upstart/gunicorn.log --log-level debug
          
          • getting the following gunicorn.log file, what could be the possible issue

             logger_class: gunicorn.glogging.Logger
            [2017-03-08 18:34:16 +0000] [3675] [INFO] Starting gunicorn 19.6.0
            [2017-03-08 18:34:16 +0000] [3675] [DEBUG] Arbiter booted
            [2017-03-08 18:34:16 +0000] [3675] [INFO] Listening at: http://127.0.0.1:8000 (3675)
            [2017-03-08 18:34:16 +0000] [3675] [INFO] Using worker: sync
            [2017-03-08 18:34:16 +0000] [3680] [INFO] Booting worker with pid: 3680
            [2017-03-08 18:34:16 +0000] [3681] [INFO] Booting worker with pid: 3681
            [2017-03-08 18:34:16 +0000] [3682] [INFO] Booting worker with pid: 3682
            [2017-03-08 18:34:16 +0000] [3675] [DEBUG] 3 workers
            [2017-03-08 18:35:42 +0000] [3675] [INFO] Handling signal: int
            [2017-03-08 18:35:42 +0000] [3680] [INFO] Worker exiting (pid: 3680)
            [2017-03-08 18:35:42 +0000] [3681] [INFO] Worker exiting (pid: 3681)
            [2017-03-08 18:35:42 +0000] [3682] [INFO] Worker exiting (pid: 3682)
            [2017-03-08 18:35:42 +0000] [3675] [INFO] Shutting down: Master
            
        • @kamstan6
          That was very little debug-info. I expected more, but looking at the timestamps, it looks like it’s starting just fine, but a minute later it shuts down - did you visit the site within that minute?

          Are you using MySQL or SQLite?

          Can you try starting it with –spew, which will show everything going on.
          http://docs.gunicorn.org/en/stable/settings.html#spew

          /home/arnold/beta_test/myenv/bin/gunicorn --workers 3 --bind 127.0.0.1:8000 techAvenue.wsgi:application --error-logfile /var/log/upstart/gunicorn.log --log-level debug --spew
          

          It might be way too much information for displaying here, but maybe the error will give you directions - otherwise you should probably paste it to pastebin.com and link here.

@hansen, thank you very much for all the help, I am trying to start the gunicorn service and getting am getting this error

start: Job failed to start

and even if I try to run restart I get

stop: Unknown instance: 
start: Job failed to start

I am suspecting that gunicorn is not started, not sure what to do, I even restarted the droplet but still getting the same error.
Sorry again for all these questions it is my first time deploying a Django app.

  • You should probably ask in a Django-based forum, since this might not be the best place for such questions.
    You need to look at your error logs - and have debugging enabled. That’s the only way to somehow get closer to a solution.
    And yes, Gunicorn service doesn’t start, that’s why it throws an error. But it can’t start because of a problem somewhere in your code.

Submit an Answer