我正在尝试使缓存在 Nginx 上工作,它是 gunicorn 的代理或直接提供静态文件。
我尝试添加:
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";
}
但当我这样做时服务器停止工作。
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;
}
}
有同样的问题这里但我不明白有帮助的评论。
可能另一个块已定义具有根集的静态文件,在这种情况下,您应该将指令添加到该块。(我知道这已经晚了 2 年,但对于未来的公民来说)– aularon
谢谢。