I have a bunch of gzipped log files I'd like to serve with nginx. I want them to be served in such a way that they're automatically inflated by the browser. I assume that means I need nginx to send the files as .gz with a text/plain header. This can be done in apache with something like:

<FilesMatch *.gz>
    ForceType text/plain

You need the HttpGzipStatic module for this. Put gzip_static on; in your config and create your .gz files. You will need to keep both the zipped and the original file, you can then request, for example, /css.css and be served the zipped /css.css.gz

| improve this answer | |
  • One minor note: it's suggested that both files' modification times (mtime) are the same. – Alexander Azarov Mar 1 '11 at 18:09
  • 2
    And you can test it's working with curl --header "Accept-Encoding: gzip" -I your_url, and without the --header to check it still serves the uncompressed file if necessary. – Tom Sep 29 '15 at 12:41
  • Aparently this approach does NOT work with indexes like index.html.gz, if you add it to list of indexes using "index index.html.gz", it will be served as a download when you try to access the "$url/". I am still looking for a solution that would make gzipped indexes browsable too. – sorin May 30 '18 at 14:43
  • original file is not needed unless you use try_files mailman.nginx.org/pipermail/nginx/2012-June/034102.html. I tried with gunzip on and try_files serverfault.com/questions/571733/… – rofrol Apr 29 '19 at 12:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.