Trolli Schmittlauch asked:
I host my Djangoproject on Nginx with uwsgi. staticfiles need to be served separately by Nginx
server {
listen 80;
server_name blog.foo.de;
location /static {
root /home/user/blog/staticfiles;
access_log off;
expires 30d;
}
location / {
include uwsgi_params;
uwsgi_pass unix:/tmp/blog.socket;
}
access_log /var/log/nginx/blog.access.log combined;
error_log /var/log/nginx/blog.error.log warn;
}
My STATIC_URL is set to http://blog.foo.de/static/
The folder /home/user/blog/staticfiles contains a folder static, where the files are collected into. so according to other posts here everything sholud work — but it doesn’t. the uwsgi part works just fine, but I only get a 404 when I try to access the static files.
My answer:
This needs some general cleanup:
- Your
server
block has twolocation /
blocks, which is not permitted; one of them will be ignored. Use only onelocation
block for any given location. - Your
server
block has noroot
defined. Make sure thatroot
is defined only in theserver
block, and not in thelocation
blocks (unless a location needs a different root).
I also recommend not turning off
the access_log
or using expires
while debugging, as this can make it more difficult to isolate the cause of a problem.
Though to really fix this, consider rewriting it entirely. A very short example:
server {
location @django {
include uwsgi_params;
uwsgi_pass unix:/tmp/blog.socket;
}
location / {
try_files $uri $uri/ @django;
}
}
View the full question and any other answers on Server Fault.
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.