Nginx – How to serve giziped text files with nginx

gzipmime-typenginx

To save space we gzip all our logs and text files and these files are browsed by the user, but these files are downloaded instead of opened in the browser, I couldn't find a way to set mime-type text/plain for such files e.g. this does not work

types {
    text/plain txt txt.gz log.gz
}

So is there a way in nginx to tell txt.gz and log.gz files are to be served as text/plain ?

Best Answer

Set up nginx gzip_static

example:

location / {
gzip_static on
}

http://nginx.org/en/docs/http/ngx_http_gzip_static_module.html