stuck on 'welcome to nginx' gunicorn django ubuntu 16.04

I am stuck on the ‘welcome to nginx’ page and I need help. Here is what I have and tried.

Test passed: gunicorn --bind myapp.wsgi:application


Description=gunicorn daemon

ExecStart=/home/jarjar/myapp/myappenv/bin/gunicorn --workers 3 --bind unix:/home/jarjar/myapp/myapp.sock myapp.wsgi:application



server {
    listen 80 default_server;
    listen [::]:80 default_server;
    return 301 https://$server_name$request_uri;

    root /home/jarjar/myapp;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /home/jarjar/myapp;

    location / {
        include proxy_params;
        proxy_pass http://unix:/home/jarjar/myapp/myapp.sock;

    location ~ /.well-known {
        allow all;

server {
    listen 443 ssl http2 default_server ;
    listen [::]:443 ssl http2 default_server;
    include snippets/;
    include snippets/ssl-params.conf;

sudo rm /etc/nginx/sites-available/default sudo systemctl start gunicorn sudo systemctl enable gunicorn sudo nginx -t sudo systemctl restart nginx


@jarjar - OK, I’ve seen the socket surrounded with colons, but maybe the parser allows dropping ending part? From the nginx documentation:

Syntax:	proxy_pass URL;
Default:	—
Context:	location, if in location, limit_except
Sets the protocol and address of a proxied server and an optional URI to which a location should be mapped. As a protocol, “http” or “https” can be specified. The address can be specified as a
```code```domain name or IP address, and an optional port:
        proxy_pass http://localhost:8000/uri/;
or as a UNIX-domain socket path specified after the word “unix” and enclosed in colons:
        proxy_pass http://unix:/tmp/backend.socket:/uri/;

What does the following command output:

ls -l /etc/nginx/sites-enabled


# If I remove 'http://' I get:
nginx: [emerg] invalid URL prefix in /etc/nginx/sites-enabled/myapp:16
nginx: configuration file /etc/nginx/nginx.conf test failed

# If I remove 'unix:/' I get:
nginx: [emerg] host not found in upstream "home" in /etc/nginx/sites-available/myapp
nginx: configuration file /etc/nginx/nginx.conf test failed

I followed this tutorial when I set up my server. He said to put:

    location / {
        include proxy_params;
        proxy_pass http://unix:/home/sammy/myproject/myproject.sock;

@jarjar - I’d double check your URL. That doesn’t look correct

    location / {
        include proxy_params;
        ## What does it mean to have both http and unix protocols
        proxy_pass http://unix:/home/jarjar/myapp/myapp.sock;

@gndo total 0 lrwxrwxrwx 1 root root 38 Jul 11 09:26 myapp -> /etc/nginx/sites-available/myapp

Also, my nginx error.log is giving me a 28 [error] 28452#28452: send() failed (111: Connection refused) while resolving, resolver:

Submit an 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.

Accepted Answer

This will never work because you’re redirecting http to https (server block with listen on 443) and there’s no location there (except if inside those includes)

If you’re running this site via http, remove the return 301 ... If you plan on serving it only in https, remove all location entries from the server entry that listens to 80 and put them inside the server block that listens to 443.

Try this:

rename your proxy_pass:

proxy_pass http://django_projectname_server;

and then, BEFORE your server entry

upstream django_projectname_server {
  server unix:/fullpath/to/sockfile.sock fail_timeout=0;