nginxcaching似乎没有与Django的工作

我有几个Django应用程序,我想尝试与NGINXcaching。 我遵循这个指南。 https://www.nginx.com/blog/nginx-caching-guide/

我使用include指令在http块中包含这一行的文件…

 proxy_cache_path /usr/share/nginx/cache levels=1:2 keys_zone=my cache:10m max_size=2g inactive=60m use_temp_path=off; 

然后我去了sites-enabled文件夹,并将其添加到我的服务器块,这些是SSL块…

 server { listen 443 ssl; server_name example.com; ssl_certificate my/path/to/ssl; ssl_certificate_key my/path/to/ssl; client_max_body_size 4G; keepalive_timeout 5; # Your Django project's media files - amend as required location /media { proxy_cache my_cache; alias /home/example/media; } # your Django project's static files - amend as required location /static { proxy_cache my_cache; alias /home/example/example/static_dump; } location / { #Next two lines added while developing includes only ip's in the file include /etc/nginx/ip-allow.conf; deny all; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off; proxy_cache my_cache; proxy_pass http://app_server_example; } 

我看到当我检查caching文件的path,它已经创build一个./tmp文件夹,所以我想权限是正确的,当我重新启动nginx与nginx -s reload ,然后service nginx restart我从来没有得到任何错误。

为什么在向我的站点发出请求后,这些caching目录中没有文件显示?

很可能您的Django应用程序返回不允许caching页面的HTTPcaching标头。

如果你想忽略Djangocaching标题,那么你可以使用这个:

 proxy_ignore_headers X-Accel-Expires Expires Cache-Control;