Ideally when serving text-based resources (HTML, CSS and JavaScript files) to your website visitors you should be serving them with compression enabled. This will minimise the time taken to download, as the larger the files are, the longer they will take to download and the longer your website visitors will have to wait to view your website content. By minimising these files your website will be faster and result in a better user experience for your visitors.
There are three different types of compression algorithms currently used; Gzip, Brotli and Deflate. When a visitors web browser requests a text-based resource it will use the Accept-Encoding HTTP request header to indicate which compression algorithm it supports. If the web browser supports all three compression algorithms it will send the request header Accept-Encoding: gzip, compress, br and then your server will return a Content-Encoding HTTP response header to show what compression algorithm has been used. If the Content-Encoding: br response header is returned by the server means the text-based resources have been compressed using the Brotli algorithm. If the Content-Encoding: gzip response header is returned by the server means the text-based resources have been compressed using the Gzip algorithm.
When using OpenLitespeed, it will show different compression algorithm response headers dependent upon the type of website being served. If the website is based on html it will return a Brotli response header but if the website is based on PHP, for example WordPress, it will return Gzip response header. This is because OpenLitespeed will only serve dynamic content (PHP) using Gzip compression algorithm. If you want to serve all dynamic content (PHP) using Brotli compression algorithm, you will need to upgrade your web server to a commercial Litespeed variant such as Site Owner, Site Owner Plus, Web Host Lite, Web Host Essential, etc.
OpenLitespeed does not use the compression algorithm Deflate as this is an Apache module and uses the Gzip and Brotli compression algorithms only. If you have used GTMetrix to measure your websites performance you may have noticed that they recommended you enable text compression and provide the necessary commands to include in your .htaccess file to enable compression. If you have tried to add these commands to your .htaccess file, you will notice that they have not worked because OpenLitespeed does not use the mod_deflate
module.
In this guide, we will show you how to add custom Compression Types to OpenLitespeed. We will also show you how you can adjust the compression levels applied to Gzip and Brotli static content. These changes are applied on a server level, therefore it will apply to all domains hosted on your DirectAdmin server by changing the server configuration file.
How to Change Default Compression Types for OpenLitespeed and DirectAdmin
- 1 Prerequisites
- 2 GZIP/Brotli Compression Types
- 3 GZIP/Brotli Compression Options
- 3.1 Enable Compression
- 3.2 Enable GZIP Dynamic Compression
- 3.3 GZIP Compression Level (Dynamic Content)
- 3.4 Auto Update Static File
- 3.5 GZIP Compression Level (Static File)
- 3.6 Brotli Compression Level (Static File)
- 3.7 Static Cache Directory
- 3.8 Max Static File Size (Bytes)
- 3.9 Min Static File Size (Bytes)
Prerequisites
As we have discussed previously in our guides, when using OpenLiteSpeed with DirectAdmin the OpenLiteSpeed admin panel is set to read only and you cannot change or edit any settings using the GUI. The reason for this is due to the way the DirectAdmin development team integrate OpenLiteSpeed. Usually the OpenLiteSpeed configuration file is one file but DirectAdmin splits this configuration file into multiple include files stored in the /usr/local/lsws/conf
directory. These all come together when using the ./build rewrite_confs
command to create one configuration file.
Important
It is not recommended to edit the OpenLiteSpeed configuration files in the /usr/local/lsws/conf
folder directly. We recommend you edit these configuration files by creating a template, a direct copy of the original OpenLiteSpeed configuration file. All global OpenLiteSpeed templates are stored in the template folder /usr/local/directadmin/data/templates
.
GZIP/Brotli Compression Types
The GZIP/Brotli Compression options are located in the Tuning section of the OpenLitespeed admin panel. In order to change these options will need to edit the httpd-tuning.conf
file located in the /usr/local/lsws/conf/
directory. However, if we edited this file directly it would be overwritten by custombuild when either the ./build openlitespeed
or ./build rewrite_confs
commands are issued.
We can utilise the facility built into custombuild that enables a custom configuration file to be used by creating a custom OpenLitespeed configuration folder and adding the httpd-tuning.conf
template file. Firstly, we will need to create the custom OpenLitespeed configuration folder using the following commands.
cd /usr/local/directadmin/custombuild/ mkdir -p custom/openlitespeed/conf
Now we will need to create the custom httpd-tuning.conf
file. We will copy the existing httpd-tuning.conf
template to the /custom/openlitespeed/conf/
directory using the following command.
cp -p configure/openlitespeed/conf/httpd-tuning.conf custom/openlitespeed/conf/
The default compression types used in OpenLitespeed with DirectAdmin are text/*, application/x-javascript, application/xml, application/javascript, image/svg+xml,application/rss+xml
. The compression type text/*
means that all compression types that start with text, for example, text/html or text/css will be compressed irrespective of the type after the /.
The list of compression types below includes the default OpenLitespeed types and the recommended compression types from GTMetrix. While the list contains both resources (OpenLitespeed and GTMetrix), it is in no way exhaustive and is shown for illustration. You should adjust the different compression types to your own preferences.
text/*, application/x-javascript, application/javascript, application/xml, application/json, application/ld+json, application/rdf+xml, application/rss+xml, application/schema+json, application/manifest+json, application/vnd.ms-fontobject, application/vnd.geo+json, application/x-font, application/x-font-opentype, application/x-font-otf, application/x-font-truetype, application/x-font-ttf, application/xhtml+xml, application/x-web-app-manifest+json, image/svg+xml, image/x-icon, image/vnd.microsoft.icon, image/bmp, font/eot, font/opentype, font/otf, font/ttf
Important
When choosing what compression types to include it is important to only allow types that will directly benefit from Gzip or Brotli compression such as . Binary files such as jpg, jpeg, png or gif images do not benefit from compression.
As we have already copied the httpd-tuning.conf
template to the /custom/openlitespeed/conf/
directory, we can add our own custom compression types to the custom httpd-tuning.conf
file. You can access the custom httpd-tuning.conf
file using the following command.
nano /usr/local/directadmin/custombuild/custom/openlitespeed/conf/httpd-tuning.conf
In the httpd-tuning.conf
file scroll down to the compressibleTypes
line and either comment it out # or delete the line totally CTRL + K. Now you can paste in the custom compression types into the httpd-tuning.conf
file and then save the file.
compressibleTypes text/*,application/x-javascript,application/javascript,application/xml,application/json,application/ld+json,application/rdf+xml,application/rss+xml,application/schema+json,application/manifest+json,application/vnd.ms-fontobject,application/vnd.geo+json,application/x-font,application/x-font-opentype,application/x-font-otf,application/x-font-truetype,application/x-font-ttf,application/xhtml+xml,application/x-web-app-manifest+json,image/svg+xml,image/x-icon,image/vnd.microsoft.icon,image/bmp,font/eot,font/opentype,font/otf,font/ttf
After saving the custom httpd-tuning.conf
file we will need to tell DirectAdmin to rebuild the OpenLitespeed configuration files and apply the custom compression types using the following command.
cd /usr/local/directadmin/custombuild/ ./build rewrite_confs
Now log into the OpenLitepseed admin dashboard. From the side menu select Server Configuration and then Tuning from the tab menu in the Server Configuration dashboard.
In the Tuning dashboard scroll down the page until you reach the GZIP/Brotli Compression section. Next to Compressible Types you will now see the custom compression types we added to the custom httpd-tuning.conf
file.
Note
If you didn’t want to specify what file types (MIME) are allowed to be compressed or want to revert to the default settings, you change this option to compressibleTypes default
and OpenLitespeed will use the built-in default list.
That’s it. You have successfully created a custom httpd-tuning.conf file and added your own compression types to OpenLitespeed. Now we will show you how to configure additional Gzip and Brotli compression options with DirectAdmin and OpenLitespeed.
GZIP/Brotli Compression Options
When you were adding your own custom compression types to the httpd-tuning.conf
file, you will have noticed that there are quite a few different options in that file other than compressibleTypes
.
Important
If the option is displayed in the OpenLitespeed admin panel as Not Set or is missing from the httpd-tuning.conf
file, it doesn’t mean that the actual option is not set within Openlitespeed. Many of the options are hardcoded (written directly into OpenLitespeed) such as the option for Static Cache Directory
. This option has the default value set as the swapping directory used by OpenLitespeed /tmp/lshttpd/swap
.
In this part of the guide we will explain what each section is and how you can adjust it. We will be focusing on the GZIP/Brotli Compression section (as shown in the Openlitespeed admin panel) and show you how you can adjust the Gzip compression level for both static and dynamic content and the Brotli compression level for static content. If the option is not listed in the httpd-tuning.conf
file you can add to the file and when you issue the ./build rewrite_confs
command custombuild will change the settings in OpenLitespeed.
Enable Compression
The Enable Compression option will enable or disable Gzip/Brotli Compression and is called enableGzipCompress
. This acts like a master switch for the sever, the default setting is Yes which equates to 1 in the settings. If you wanted to disable (Set to No) compression server-wide you can change this setting to 0. We wouldn’t recommend you disable this option, as it will save bandwidth and improve website user experience by compressing html, css and javascript files up to half of their original size.
enableGzipCompress 1
Enable GZIP Dynamic Compression
The Enable GZIP Dynamic Compression option will enable or disable Gzip dynamic compression and is called enableDynGzipCompress
. The setting will enable or disable GZIP compression for dynamically generated responses. The default setting is On which equates to 1 in the configuration file. If you wanted to disable (Set to No) dynamic Gzip compression server-wide you can change this setting to 0. We wouldn’t recommend you disable this option, as it will save server bandwidth and improve website user experience by compressing dynamic content such as those generated by a WordPress website.
enableDynGzipCompress 1
GZIP Compression Level (Dynamic Content)
The GZIP Compression Level (Dynamic Content) option specifies the level of compression applied to dynamic Gzip content and is called gzipCompressLevel
. The default compression level setting is 6. The levels range from 1 (lowest) to 9 (highest). The higher you set the compression level, the smaller the files will become but it will use more server resources particularly CPU and memory. It has been shown there is no real difference between level 6 and 9 on html, css and javascript files, other than level 9 using more server resources.
gzipCompressLevel 6
Auto Update Static File
The Auto Update Static File option specifies whether to allow Gzip compressed versions of compressible static files to be created or updated automatically and is called gzipAutoUpdateStatic
. The default setting is Yes which equates to 1 in the configuration file. If this option is enabled when a file type listed in the compressibleTypes section is requested, the server will create or update the orresponding compressed version of the static file and the filename is based on a MD5 hash of the path of the original file. If you wanted to disable (Set to No) automatically creating or update static files server-wide you can change this setting to 0, although this is not recommended.
gzipAutoUpdateStatic 1
GZIP Compression Level (Static File)
The GZIP Compression Level (Static File) option specifies the level of compression applied to static Gzip content and is called gzipStaticCompressLevel
. The default compression level setting is 6. The levels range from 1 (lowest) to 9 (highest). This option works in the same way as the Gzip compression level for dynamic content; the higher you set the compression level, the smaller the html, css, and javascript files will become but it will use more server resources particularly CPU and memory. This option will only take effect when “Enable GZIP Compression” and “Auto Update Static File” are enabled.
gzipStaticCompressLevel 6
Brotli Compression Level (Static File)
The Brotli Compression Level (Static File) option specifies the level of compression applied to static Brotli content and is called brStaticCompressLevel
. The default compression level setting is 5 and is hardcoded into OpenLitespeed i.e. there is no default option in the httpd-tuning.conf
file, however you can add it using the command below. The levels range from 1 (lowest) to 11 (highest) or you can set 0 which will disable brotli compression globally. This option works in the same way as the Gzip compression level for static and dynamic content; the higher you set the compression level, the smaller the html, css, and javascript files will become but it will use more server resources particularly CPU and memory.
brStaticCompressLevel 5
Static Cache Directory
The Static Cache Directory option specifies the directory that is used to store the Gzip/Brotli compressed static content files and is called gzipCacheDir
. The default directory setting is /tmp/lshttpd/swap and is hardcoded into OpenLitespeed i.e. there is no default option in the httpd-tuning.conf
file, however you can add it using the command below. If you wanted to change the directory you will need to add the full directory path and not just a folder name. We wouldn’t recommend you change this option and leave it as the default option.
gzipCacheDir /tmp/lshttpd/swap
Max Static File Size (Bytes)
The Max Static File Size (Bytes) option specifies the maximum size of a static file that OpenLitespeed will compress automatically and is called gzipMaxFileSize
. The default maximum file size is 10M. It is not recommended to set the maximum size too high as the server will need to create or update the compressed files. When OpenLitespeed is compressing files it uses an entire server process and blocks any further requests until the compression has been completed. If you wanted to change the maximum file size to 20MB, you will need to change the setting from 10M to 20M. Although we would recommend that you leave this value set as the default option.
gzipMaxFileSize 10M
Min Static File Size (Bytes)
The Min Static File Size (Bytes) option specifies the minimum size of a static file that OpenLitespeed will compress automatically and is called gzipMinFileSize
. The hard-coded OpenLitespeed default minimum file size is set at 200 i.e. you cant go below this number, however, the DirectAdmin default is set at 300. This means that any file that is smaller than 300KB will not be automatically compressed as it is not necessary to compress very small files as the bandwidth saving is negligible. If you wanted to change the minimum file size to 200KB, you will need to change the setting from 300 to 200. Although we would recommend that you leave this value set as the default option.
gzipMinFileSize 300
That’s it. You have successfully created a custom httpd-tuning.conf file and added your own compression types to OpenLitespeed. You now have an understanding of the different GZIP/Brotli compression options in OpenLitespeed and how to adjust them using DirectAdmin.
2 Comments for How to Change Default Compression Types for OpenLitespeed and DirectAdmin
Great post for a newbie like me. Thanks
Hi Sharath
Thanks for the feedback.
Kind Regards
VPSBasics