6.3.8 How to enable caching and GZip compression for a website on VPS

Enabling caching and GZip compression using the ISPManager panel

On shared hosting servers and starting with the Ubuntu18+ispmgr OS template, caching and compression can be enabled for the desired domain in the hosting control panel. To do this, in the ISP panel you need to go to the “WWW domains” section, select the domain and click the “Change” button.

Next, you just need to enable what you need, as shown in the figure below:

Как включить кеширование и GZip сжатие

Enabling caching and GZip compression on servers without using the control panel

For virtual and dedicated server services caching and compression must be enabled manually. It is necessary to enter the following lines in the Nginx configuration file (/etc/nginx/nginx.conf) within the server directive for the desired site:

expires 7d;
gzip on;
gzip_min_length 1000;
gzip_proxied any;
gzip_types text/plain text/xml application/xml application/x-javascript text/javascript text/css text/json;
gzip_disable "msie6";
gzip_comp_level 6;

You need to add the following lines immediately after the directive:

location ~* ^.+\.(jpg|jpeg|gif|png|svg|js|css|mp3|ogg|mpe?g|avi|zip|gz|bz2?|rar|swf)$ {

Example block with settings in the Nginx configuration file

	server {
		server_name examplesite.com;
		listen 91.234.32.170;
		listen 91.234.32.170:443 ssl;
		disable_symlinks if_not_owner from=$root_path;
		set $root_path /var/www/exampleuser/data/www/examplesite.com;
	location ~* ^.+\.(jpg|jpeg|gif|png|svg|js|css|mp3|ogg|mpe?g|avi|zip|gz|bz2?|rar|swf)$ {
		expires 7d;
		gzip on;
		gzip_min_length 1000;
		gzip_proxied any;
		gzip_types text/plain text/xml application/xml application/x-javascript text/javascript text/css text/json;
		gzip_disable "msie6";
		gzip_comp_level 6;
		root $root_path;
		access_log /var/www/nginx-logs/exampleuser isp;
		access_log /var/www/httpd-logs/examplesite.com.access.log ;
		error_page 404 = @fallback;
}

After adding the specified lines, you need to save the Nginx configuration file and reload it with the command:

  1. /etc/init.d/nginx restart