我无法使用 Nginx proxy_cache 功能,尽管我的服务器配置似乎根据官方指南。我这里遗漏了什么吗?
Vhost配置:
proxy_cache_path /var/www/nginx_cache levels=1:2 keys_zone=asf:1m max_size=64m
inactive=60m use_temp_path=off;
server {
listen 443 ssl;
server_name my_domain.com;
root /var/www/my_site;
index index.php index.html;
include /etc/nginx/snippets/lets_encrypt_challenge.conf;
location / {
try_files $uri /controller.php$is_args$args;
}
location ~* \.(js|css|png|jpe?g|gif|ico|woff2?|eot)$ {
expires 7d;
add_header Cache-Control "public, no-transform";
}
location ~* ^/[^/]+\.php {
proxy_cache asf;
proxy_cache_lock on;
# The PHP application sets a cache-control header which disables
# caching mechanism by default. So next directive is required to tell to ignore this header.
proxy_ignore_headers Cache-Control;
add_header X-Proxy-Cache $upstream_cache_status always;
fastcgi_split_path_info ^([^/]+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index controller.php;
include fastcgi_params;
fastcgi_param DOCUMENT_ROOT $realpath_root;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_intercept_errors on;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
fastcgi_connect_timeout 180;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
}
}
响应头包(甚至不包含X-Proxy-Cache
为了跟踪缓存是否被命中而添加的内容):
Cache-Control: public, max-age=84600
Connection: keep-alive
Content-Encoding: gzip
Content-Type: text/html; charset=UTF-8
Date: Sun, 04 Feb 2018 18:42:18 GMT
Server: nginx
Transfer-Encoding: chunked
谢谢。