Question

Nginx + Gunicorn. Static Files won't load.

  • Posted on April 1, 2014
  • kpennellAsked by kpennell

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


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.

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