By konkhra
Hi all!
I have a Wordpress website where I am trying to serve through nginx, gzip pre-compressed html files generated by Wp Super Cache plugin and for that I created a location directive with special headers and gzip off. For an unknown reason to me nginx is not taking in consideration the content-header options and whenever I access a page Firefox is attempting to download gz files.
Could you please tell me what am I doing wrong?
Nginx is not throwing errors.
# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
I really appreciate your help!
Here is the code:
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;
}
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hi @konkhra
It is not really clear on what you want to do exactly. The Gzip part in your Nginx would tell basically add a Gzip header. The .gz files that you are accessing are simply gziped files. The two things are kind of not related directly.
To test if the gzip off is working you could check the headers when accessing your /wp-content/cache/supercache.*gz URL:
curl -IL yourdomain.com/wp-content/cache/supercache.somefile.gz
If you do not see the gzip header, then the location rules are working as expected.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.