我对nginx try_files语法有疑问。
我有一个Wordpress网站,我在下面编写了nginx规则,以读取* .html和* .gz文件,并且在找不到这些文件时将其重定向到php-fpm。
由于某些原因,当nginx提供* .gz缓存文件时,它不考虑使用location ~ /wp-content/cache/supercache.*gz$
来添加适当的标头,并且浏览器在{{1}中显示*.gz
存档内容}格式不是text/plain
,因为它是在位置中设置的。
text/html
我发现了一个重写规则,该规则考虑了 set $full_cachefile '/wp-content/cache/supercache/$http_host${condition}';
set $cachefile $full_cachefile${uri}index-https.html;
set $gzipcachefile $full_cachefile${uri}index-https.html.gz;
location ~ /wp-content/cache/supercache.*html$ {
add_header Vary "Accept-Encoding, Cookie";
add_header Pragma "public";
add_header Cache-Control "max-age=3600, public";
}
location ~ /wp-content/cache/supercache.*gz$ {
gzip off;
types {}
default_type text/html;
add_header Vary "Accept-Encoding, Cookie";
add_header Pragma "public";
add_header Cache-Control "max-age=3600, public";
add_header Content-Encoding gzip;
}
location / {
try_files $gzipcachefile $cachefile $uri $uri/ /index.php$is_args$args;
}
位置的标头,但是如果在缓存文件夹nginx中找不到~ /wp-content/cache/supercache.*gz$
或*.html
文件,则会抛出404错误。
*.gz
有人知道如何使用try_files或重写规则解决该问题吗?