Only compressed version of file on server , and supporting clients that don't send Accept-Encoding.

Maxim Dounin mdounin at mdounin.ru
Fri Mar 23 00:38:13 UTC 2018


Hello!

On Thu, Mar 22, 2018 at 05:00:20PM -0700, Hemant Bist wrote:

> Hi,
> We have only gzipped files stored on nginx and need to serve client that :
> A) Support gzip transfer encoding (> 99% of the clients). They send
> Accept-Encoding: gzip header...
> B) < 1% of the clients that don't support transfer encoding. The don't send
> Accept-Encoding header.
> 
> There is ample CPU in the nginx servers to support clients of type B).  But
> I am unable to figure out a config/reasonable script
> to help us serve these clients.
> 
> Clients of type A) are served with the following config.
> --- Working config that appends .gz in the try_files ----
>     location /compressed_files/ {
>         add_header Content-Encoding "gzip";
>         expires    48h;
>         add_header Cache-Control private;
>         try_files $uri.gz @lua_script_for_missing_file;
>     }
> 
> 
> ----- Not working  config  with gunzip on; likely because gunzip filter
> runs before add_header?
> 
>     location /compressed_files/ {
>         add_header Content-Encoding "gzip";
> 
>         expires    48h;
>         add_header Cache-Control private;
> *# gunzip on fails to uncompress likely because it does not notice the
> add_header directive.*
> *        gunzip on;*
> *        gzip_proxied any;*
>         try_files $uri.gz @lua_script_for_missing_file;
>     }
> 
> 
> I would appreciate any pointers on how to do this. I may be missing some
> obvious configuration for such case.
> We did discuss keeping both unzipped and zipped version on the server, but
> unfortunately that is unlikely to happen.

Try this instead:

    location /compressed_files/ {
        gzip_static always;
        gunzip on;
    }

See documentation here for additional details:

http://nginx.org/r/gzip_static
http://nginx.org/r/gunzip

Note that you wan't be able to combine this with "try_files 
$uri.gz ...", as this will change URI as seen by gzip_static and 
will break it.  If you want to fall back to a different location 
when there is no file, use "error_page 404 ..." instead.

-- 
Maxim Dounin
http://mdounin.ru/


More information about the nginx mailing list