20

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>

1 Answer 1

26

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

4
  • One minor note: it's suggested that both files' modification times (mtime) are the same. Mar 1, 2011 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, 2015 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, 2018 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, 2019 at 12:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .