我的nginx缓存不起作用。我已经按照一些答案仍然没有工作。有人能帮助我吗?
我忽略了标题:缓存控制,Set-Cookies,但不起作用。
我的缓存网址: https://p.rmiao.top/proxy/bing/HPImageArchive.aspx?format=js&idx=0&n=2
我的请求标题:
:authority: p.rmiao.top
:method: GET
:path: /proxy/bing/HPImageArchive.aspx?format=js&idx=0&n=2
:scheme: https
accept: application/json, text/javascript, */*; q=0.01
accept-encoding: gzip, deflate, br
accept-language: zh-CN,zh;q=0.9,zh-TW;q=0.8
cache-control: no-cache
origin: https://www.cnblogs.com
pragma: no-cache
referer: https://www.cnblogs.com/woshimrf/p/java-list-distinct.html
user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6)
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36
我的回复标题:
access-control-allow-credentials: true
access-control-allow-headers: Cache-Control, reqid, nid, host, x- real-ip, x-forwarded-ip, event-type, event-id, accept, content-type
access-control-allow-methods: GET, POST, OPTIONS, DELETE
access-control-allow-origin: https://www.cnblogs.com
access-control-max-age: 2592000
cache-control: public, max-age=604800
content-encoding: gzip
content-length: 771
content-type: application/json; charset=utf-8
date: Mon, 16 Apr 2018 09:13:24 GMT
server: nginx/1.12.2
status: 200
x-cache-status: MISS
我的nginx配置:
proxy_cache_path /tmp/nginx/cache levels=1:2 keys_zone=bing_cache:10m max_size=1g inactive=48h use_temp_path=off;
server {
listen 443 ssl http2;
server_name p.rmiao.top;
location ^~/proxy/bing/ {
proxy_cache bing_cache;
proxy_ignore_headers vary X-Accel-Expires Expires Cache-Control Set-Cookie;
proxy_hide_header Set-Cookie;
proxy_hide_header Cache-Control;
proxy_hide_header p3p;
proxy_hide_header server;
proxy_hide_header date;
proxy_hide_header x-msedge-ref;
proxy_hide_header vary;
add_header X-Cache-Status $upstream_cache_status;
valid_referers none blocked *.cnblogs.com server_names ~\.rmiao\.;
if ($invalid_referer) {
return 403;
}
add_header 'Access-Control-Allow-Origin' "$http_origin";
add_header 'Access-Control-Allow-Credentials' "true";
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, DELETE';
add_header 'Access-Control-Allow-Headers' 'Cache-Control, reqid, nid, host, x-real-ip, x-forwarded-ip, event-type, event-id, accept, content-type';
add_header 'Access-Control-Max-Age' 2592000;
add_header 'Cache-Control' "public, max-age=604800";
if ( $request_method = "OPTIONS" ) {
return 204;
}
rewrite ^/proxy/bing/(.*)$ /$1 break;
proxy_pass https://cn.bing.com;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
ssl_certificate /etc/letsencrypt/live/p.rmiao.top/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/p.rmiao.top/privkey.pem; # managed by Certbot
}
答案 0 :(得分:0)
我通过重启nginx服务来解决此问题。 我猜proxy_cache_path配置需要重新启动才能使用,并且nginx -s reload可能无法正常工作。 希望对您有所帮助。