Report this

What is the reason for this report?

Nginx + Gunicorn. Static Files won't load.

Posted on April 1, 2014

Did these two tutorials and can’t get my Mezzanine static files to load: https://www.digitalocean.com/community/articles/how-to-install-and-configure-django-with-postgres-nginx-and-gunicorn#tutorial-comment-submit https://www.digitalocean.com/community/articles/how-to-install-and-get-started-with-django-based-mezzanine-cms-on-ubuntu

Triple checked my settings and can’t find why my static files aren’t loading.

Nginx and Gunicorn are installed and working. Symbolic Link between sites-available and sites-enabled is made

── sites-available │ ├── mezzanine_app │ └── myproject ├── sites-enabled │ ├── ahalearning -> …/sites-available/ahalearning │ ├── mezzanine_app -> …/sites-available/mezzanine_app │ └── myproject -> …/sites-available/myproject

Collectstatic has been run and static files are in place:

├── deploy │ ├── crontab │ ├── gunicorn.conf.py │ ├── live_settings.py │ ├── nginx.conf │ └── supervisor.conf ├── dev.db ├── fabfile.py ├── init.py ├── init.pyc ├── local_settings.py ├── local_settings.pyc ├── manage.py ├── requirements.txt ├── settings.py ├── settings.pyc ├── static │ ├── admin │ ├── css │ ├── filebrowser │ ├── fonts │ ├── grappelli │ ├── img │ ├── js │ ├── media │ ├── mezzanine │ ├── robots.txt │ └── test ├── urls.py ├── urls.pyc └── wsgi.py

STATIC_ROOT in settings.py points to the right folder (opt/myenv/mezzanine_app/static/)

My nginx server settings point to the right files: /etc/nginx/sites-available

server { server_name 107.170.215.138;

    access_log off;

    location /static/ {
        alias  /opt/myenv/mezzanine_app/static/;
    }

    location / {
            proxy_pass http://127.0.0.1:8001;
            proxy_set_header X-Forwarded-Host $server_name;
            proxy_set_header X-Real-IP $remote_addr;
            add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM NAV"';
    }
}

Nginx and Gunicorn fire up without problems.

Nginx Error Log:

2014/04/01 07:10:27 [error] 20899#0: *97 connect() failed (111: Connection refused) while connecting to upstream, client: 220.181.51.145, server: 107.170.215.138, request: "GET / H$ $: “HEAD / HTTP/1.0”, upstream: “http://127.0.0.1:8001/” 2014/04/01 07:54:00 [error] 20899#0: *101 connect() failed (111: Connection refused) while connecting to upstream, client: 173.234.241.50, server: 107.170.215.138:8001, request: "G$ 2014/04/01 08:09:25 [error] 20899#0: *103 connect() failed (111: Connection refused) while connecting to upstream, client: 61.135.190.199, server: 107.170.215.138, request: "GET / $ 2014/04/01 09:14:13 [error] 20899#0: *105 connect() failed (111: Connection refused) while connecting to upstream, client: 220.181.51.150, server: 107.170.215.138, request: "GET / $ 2014/04/01 10:16:23 [error] 20899#0: *107 connect() failed (111: Connection refused) while connecting to upstream, client: 61.135.190.199, server: 107.170.215.138, request: "GET / $ 2014/04/01 11:15:52 [error] 20899#0: *109 connect() failed (111: Connection refused) while connecting to upstream, client: 220.181.51.150, server: 107.170.215.138, request: "GET / $ 2014/04/01 12:08:57 [error] 20899#0: *111 connect() failed (111: Connection refused) while connecting to upstream, client: 201.57.75.254, server: 107.170.215.138:8001, request: "H



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.

Try removing the trailing slashes. A trailing slash tells nginx that it should look for a directory, not a file.

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.