戴着我的系统管理员帽子,我的一个应用程序开发人员给我这个问题:
在他的app目录中,他在app/assets/javascripts和app/public/javascripts中有javascript文件.在public/javascripts目录中,有未压缩和.gz文件.期望是nginx将服务于javascripts的压缩版本.
在应用程序的nginx配置文件中,我添加了这个:
location /javascripts {
gzip on;
gzip_static on;
try_files /srv/app_dir/current/public/$uri /srv/app_dir/current/assets/$uri;
}
Run Code Online (Sandbox Code Playgroud)
使用这些参数,应用程序工作正常.找到并提供所有.js文件.但是nginx从未找到并提供文件的gzip版本.
有任何疑难解答吗?
Nginx 1.6 上不需要未压缩的文件:
location ~ \.txt$ {
gzip_static on;
gunzip on;
}
Run Code Online (Sandbox Code Playgroud)
现在两者curl http://localhost/index.txt都可以在我的根目录中curl -H "Accept-Encoding: gzip" http://localhost/index.txt | gunzip找到。/srv/www/localhost/index.txt.gz