Nginx try_files和重写规则,以使用适当的标头从特定位置提供html或gzip缓存文件

我对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,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或重写规则解决该问题吗?

qingabc 回答:Nginx try_files和重写规则,以使用适当的标头从特定位置提供html或gzip缓存文件

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3157542.html

大家都在问