NGINX location directive - Not serving gzip pre-compressed files

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-wontent/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;
}

1 Reply

Linode Staff

You may need to try using gzip_static rather than your current configuration. This module enables checking for pre-compressed files. The Nginx website has more information here; there are several flags you can use to optimize it for your use case. Make sure to restart Nginx after making these changes so they're picked up immediately :)

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct