Django 1-click install 502 bad gateway

I’ve just started with Django’s 1-click install running on Ubuntu 16.04. My IP address works, but the domain doesn’t. I only have IPV4 enabled. I have the correct A record enabled and the NS set up.

But when I access the domain I get 502 bad gateway error. I spun this droplet up last night, so the details should have propagated.

I am getting the following nginx errors in the logs:

2017/01/11 18:11:40 [error] 3002#3002: *1 upstream prematurely closed connection while reading response header from upstream, client:, server: _, request: "GET / HTTP/1.1", upstream: "http://unix:/home/django/gunicorn.socket:/", host: ""
2017/01/11 18:11:41 [error] 3002#3002: *1 upstream prematurely closed connection while reading response header from upstream, client:, server: _, request: "GET /favicon.ico HTTP/1.1", upstream: "http://unix:/home/django/gunicorn.socket:/favicon.ico", host: "", referrer: ""

I don’t know but I’m assuming this is a Gunicorn issue (I’m new to Gunicorn so don’t know though), my nginx looks like this, I’ve commented things that i’ve added

# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# Generally, you will want to move this file somewhere, and start with a clean
# file but keep this around for reference. Or just disable in sites-enabled.
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.

# Default server configuration
# I added this based off
upstream app_server {
    server fail_timeout=0;
server {
        listen 80 default_server;
        listen [::]:80 default_server;

# I added this for let's encrypt
location ~ /.well-known {
                allow all;

        # SSL configuration
        # listen 443 ssl default_server;
        # Note: You should disable gzip for SSL traffic.
        # See:
        # Read up on ssl_ciphers to ensure a secure configuration.
        # See:
        # Self signed certs generated by the ssl-cert package
        # Don't use them in a production server!
        # include snippets/snakeoil.conf;

        root /var/www/html;

        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;

        server_name _;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;

        # pass the PHP scripts to FastCGI server listening on
        #location ~ \.php$ {
        #       include snippets/fastcgi-php.conf;
        #       # With php7.0-cgi alone:
        #       fastcgi_pass;
        #       # With php7.0-fpm:
        #       fastcgi_pass unix:/run/php/php7.0-fpm.sock;

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #location ~ /\.ht {
        #       deny all;
# Virtual Host configuration for
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#server {
#       listen 80;
#       listen [::]:80;
#       server_name;
#       root /var/www/;
#       index index.html;
#       location / {
#               try_files $uri $uri/ =404;
#       }

The link doesn’t seem to have the correct paths for my 1-click, for example it references: /etc/init/gunicorn.conf. Which I don’t seem to have.

I just ran: sudo netstat -plunt | grep gunicorn

And nothing was returned. I assumed this should return something if it was running? I also ran: service gunicorn start and it started once I put my password in, but netstat returns nothing.?

I’m at a bit of a loss here, in where to go and what’s wrong. I kinda expected the one click to go a bit more smoothly. To my knowledge I haven’t done anything that would break it.

Thanks :)

Show comments

Submit an answer

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!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Update Feb 2018:

I had the same problems as you with the one click droplet:

Summary of my solution:

ALLOWEDHOSTS = [ ‘domainname’, ‘dropelt_IP’]

and add the bottom of

change: ALLOWEDHOSTS = ipaddresses()


ALLOWEDHOSTS += ipaddresses()

Kind regards Moritz

I just did:

sudo systemctl daemon-reload sudo systemctl restart gunicorn

This comment has been deleted