I'm trying to make cache work on a Nginx which is a proxy for gunicorn or which serves directly static files.
I tried to add:
location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
root /home/admin/kids/app/static;
expires 30d;
add_header Pragma public;
add_header Cache-Control "public";
}
But when I do that the server stops working.
server {
listen 80;
server_name example.com;
gzip_static on;
gzip on;
gzip_http_version 1.0;
gzip_proxied any;
gzip_min_length 500;
gzip_disable "MSIE [1-6]\.";
gzip_types text/plain text/html text/xml text/css
text/comma-separated-values
text/javascript application/x-javascript
application/atom+xml;
location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
root /home/admin/kids/app/static;
expires 30d;
add_header Pragma public;
add_header Cache-Control "public";
}
# Handle all locations
location / {
try_files $uri @proxy_to_app;
}
location @proxy_to_app {
# Pass the request to Gunicorn
proxy_pass http://127.0.0.1:8000;
# Set some HTTP headers so that our app knows where the
# request really came from
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
There was the same problem here but I don't understand the comment which helps out.
Probably another block had definition for the static files with a root set, in that case you should add the directives to that block. (I know this is 2y late, but for future citizens) – aularon
Thanks.