skip to Main Content

I can enable nginx gzip compression for MIME types. I however need to serve large files which have a different extension (.roadData). A .roadData is essentially json.

How can I ask nginx to serve .roadData files with compression?

Thanks

2

Answers


  1. add mime type for your extension

    types {
     application/json roadData;
    }
    

    enable compression for your mime type

    gzip_static  on;
    gzip  on;
    gzip_types  application/json;
    

    to offload nginx from dynamic compression create .gz (filename.roadData.gz) files next to original files so nginx will response with pre-compressed files.

    Login or Signup to reply.
  2. You can specify the MIME type for your custom extensions, like the following:

    http {
        include /etc/nginx/mime.types;
        types {
            application/json roadData;
        }
    }
    

    Then all the .roadData files will be served with the appropriate MIME type, and NGINX will compress them if you have specified that type for compression.

    In this way, you extend the server-wide MIME-types with your own, for another extension.

    Alternatively, you can specify it as default for location, provided that roadData are stored in a single directory withou other files:

    location /download/ {
        types        { }
        default_type application/json;
    }
    

    Like the other answer mentions, pre-compressed gzip files make sense there, because you don’t want NGINX to recompress those large files on every request.

    Use gzip_static on; and create a compressed version of the files.

    One of the most efficient tools there would be zopfli.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search