Can't get nginx to serve collected static files
django, gunicorn, nginx, static-files
Solution
This question gets asked quite a lot on here...
location /static/ {
alias /var/www/startupsearch_live/livestatic/;
}
Using `root` the way you had it would make a request for `/static/foo.jpg` resolve to `/var/www/startupsearch_live/livestatic/static/foo.jpg`
`alias` doesn't append the location to it. It one-for-one maps it as-is.
Problem
I am trying to get nginx to work alongside gunicorn. I have a directory `/project/static/` where static files are. Those files are collected into a directory `/project/livestatic/` using the `settings.py` configuration shown: ``` STATIC_ROOT = '/project/livestatic' STATIC_URL = '/static/' STATICFILES_DIRS = ( '/project/static', ) ``` I'm using the following nginx config: ``` worker_processes 1; user nobody nogroup; pid /tmp/nginx.pid; error_log /tmp/nginx.error.log; events { worker_connections 1024; accept_mutex off; } http { include mime.types; default_type application/octet-stream; access_log /tmp/nginx.access.log combined; sendfile on; upstream app_server { server 127.0.0.1 fail_timeout=0; } server { listen 80 default; client_max_body_size 4G; server_name domain.org; keepalive_timeout 5; # path for static files location /static/ { autoindex on; root /var/www/startupsearch_live/livestatic/; } location / { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off; proxy_pass http://127.0.0.1:8888; } } } ``` Under the development server (ignoring nginx), this configuration works fine and I can serve static files by linking to them in the format `/static/file.extension`. However, the moment nginx/gunicorn come into play, this doesn't work, and attempting to access `domain.org/static/` gives a django 404 page, signifying that nginx straight up isn't serving the files at all. How have I gone wrong?