Deliver compressed Files with zopfli & nginx

Operating system: ubuntu
OS version: 20.04

Anybody here has an nice strategy to serve compressed Files with zopfli instead of gzip?

My Idea is to have something like an cronjob or deployment-hook.
If files are uploaded to the Webspace, the server will generate zip-files from content like *.html, *.css *.js *.jpg *.png.

If in Nginx the directive:
gzip_static on; was set, it should serve the compressed (zipped) files instead of the uncompressed by default.

What do you think is the best way to automate those steps?

find /home/domain/public_html -type f -regextype posix-extended -iregex '.*\.(css|csv|html?|js|jpg|png|svg|txt|xml)' -exec zopfli '{}' \;

If you have ‘gzip_static on;’, then ‘gzip off;’ disables dynamic compression, but not static compression.

Example config:

events {
        worker_connections 1024;
        use epoll;

http {
        # Enable static gzip
        gzip_static on;

        # Disable dynamic compression (optional, and not recommended if you're proxying)
        gzip off;

        sendfile on;

        server {
                listen localhost:80;

                # Stuff being served here

hey calport, thanks, nice hint.

Can you explain, what’s you mean with the comment proxying above gzip off and why not recommended then?

Prolly due to something here

Hi, sure, upload zipped files to that platform perhaps if you looking for some more complicated things - you could ask directly zopfli devs - dont get me wrong but this issue have nothing to do with virtualmin be it on ubuntu or debian or centos not even with apache. Or perhaps write bash script which you will run every hour or even every 10 minutes to produce the results - regardless apache or nginx…

its trivial and results can be found on google as well… once again, nothing to do with virtualmin.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.