当我把这个在我的nginx.conf的http块中:
map $query_string $bye_cache { default ""; ~*nocache=1 "1"; }
并尝试与我的主机conf位置块中的variables一直工作“”,即使我打电话的URL?nocache = 1
我的块看起来像:
location ~* \.(jpg|jpeg|gif|png|svg|css|js|ico|xml|woff|woff2|eot|ttf)$ { access_log off; log_not_found off; set $expire "1d"; set $cachecontrol "public"; set $maxage "86400"; if ($bye_cache = "1") { set $expire "-1"; set $cachecontrol "no-cache"; set $maxage "0"; } autoindex off; gzip_static on; gzip_min_length 1000; gzip_comp_level 2; expires $expire; add_header Pragma "public"; add_header Cache-Control "$cachecontrol"; add_header Cache-Control "max-age=$maxage, public, must-revalidate, proxy-revalidate"; }
当我放
map $query_string $bye_cache { default "1"; ~*nocache=1 "1"; }
位置块中的if条件起作用。 我在做什么错我试过各种正则expression式已经
更新:
我想我明白了为什么这不会工作的地图将执行的位置,显然它不会匹配,因为没有nocache arg目前。 我只出现在顶层位置/。 如果是这样,我需要重写或设置在该位置,但variables之间的位置无效,并且:
#if ($args ~* "nocache=1") { # rewrite ^((.*)\.(jpg|jpeg|gif|png|svg|css|js|ico|xml|woff|woff2|eot|ttf|txt))$ $1&nocache=1 last; # set $args $args&nocache=1; #}
在位置/