我有一个 Wordpress 网站,我尝试通过 nginx 提供服务,由 WP Super Cache 插件生成的 gzip 预压缩 html 文件,为此我创建了一个带有特殊标头和 gzip 关闭的位置指令。由于我未知的原因,nginx 没有考虑内容标头选项,每当我访问页面时,Firefox 都会尝试下载 gz 文件。
你能告诉我我做错了什么吗?
Nginx 不会抛出错误。
# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
我真的很感谢你的帮助!
这是代码:
set $full_cachefile '/wp-content/cache/supercache/$http_host${condition}';
set $full_gzipcachefile '/wp-content/cache/supercache/$http_host${condition}';
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 / {
set $cachefile $full_cachefile${uri}index-https.html;
set $gzipcachefile $full_cachefile${uri}index-https.html.gz;
try_files $gzipcachefile $cachefile $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_buffers 256 16k;
fastcgi_buffer_size 128k;
fastcgi_connect_timeout 3s;
fastcgi_send_timeout 120s;
fastcgi_read_timeout 120s;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
reset_timedout_connection on;
include fastcgi_params;
#fastcgi_pass 127.0.0.1:9012;
fastcgi_pass unix:/tmp/lunarp.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
#fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}