17

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
</FilesMatch>
peter-b
  • 103
  • 5
Ben
  • 171
  • 1
  • 1
  • 3

1 Answers1

25

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

adamse
  • 421
  • 3
  • 5
  • One minor note: it's suggested that both files' modification times (mtime) are the same. – Alexander Azarov Mar 01 '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` http://mailman.nginx.org/pipermail/nginx/2012-June/034102.html. I tried with `gunzip on` and `try_files` https://serverfault.com/questions/571733/nginx-gzip-static-why-are-the-non-compressed-files-required/965094#965094 – rofrol Apr 29 '19 at 12:16