为了节省空间,我们gzip所有的日志和文本文件,这些文件被用户浏览,但这些文件被下载,而不是在浏览器中打开,我找不到一种方法来设置这种文件的MIMEtypes的text/plain例如这不起作用
types { text/plain txt txt.gz log.gz }
那么nginx有没有办法告诉txt.gz和log.gz文件要作为text/plain ?
设置nginx gzip_static
例:
location / { gzip_static on }
http://nginx.org/en/docs/http/ngx_http_gzip_static_module.html
这工作对我来说,基本上匹配基于txt.gz扩展的位置,然后对于这样的文件,设置正确的编码和MIMEtypes:
location ~* /my/data/.*txt.gz$ { add_header Content-Encoding gzip; gzip off; types { text/plain gz; }; root /; }
Nginx不能在提供这些文件之前解压缩这些文件。 你需要某种脚本来为你做这个,然后把结果提供给用户。 试图强制.gz文件作为文本只会导致垃圾输出。