Report this

What is the reason for this report?

NGINX location directive - Not serving gzip pre-compressed files

Posted on October 31, 2019

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

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Start building today

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.