2012-06-16 33 views
4

穿着我的系统管理员的帽子,我的应用程序开发人员一个递给我这个问题:nginx的与try_files和gzip_static仅用未压缩

在他的app目录,他已经在app /资产/ JavaScript和应用程序/公共javascript文件/ JavaScript的。在public/javascripts目录中,有未压缩的和.gz文件。期望的是,nginx将服务器的压缩版本的JavaScript。

在该应用的nginx的配置文件,我已经添加了这一点:

location /javascripts { 
    gzip on; 
    gzip_static on; 
    try_files /srv/app_dir/current/public/$uri /srv/app_dir/current/assets/$uri; 
    } 

有了这些参数,应用程序工作正常。所有的.js文件都被找到并提供服务。但nginx永远不会找到并提供gzip版本的文件。

对此进行故障排除的任何建议?

+0

我nginx的构建:nginx的-V:nginx的版本:nginx的/ 0.8.54 由GCC 4.4.3(Ubuntu的4.4.3-4ubuntu5.1) 建启用TLS SNI支持 配置参数:--prefix =/opt/nginx-0.8.54 --conf-path =/etc/nginx/nginx.conf --with-http_ssl_module --with-http_realip_module --with-http_gzip_static_module - -with-http_stub_status_module --add-module =/var/chef/cache/headers-more-nginx-module --add-module =/var/chef/cache/chunkin-nginx-module – Mojo

回答

0

未压缩的文件并不需要对Nginx的1.6有:

location ~ \.txt$ { 
     gzip_static on; 
     gunzip on; 
    } 

两个curl http://localhost/index.txtcurl -H "Accept-Encoding: gzip" http://localhost/index.txt | gunzip现在的工作找到刚刚/srv/www/localhost/index.txt.gz在我的根目录。

0

我刚刚尝试了@hendry在nginx/1.13.8上的答案,它不起作用。它开始工作时,我总是使用“gzip_static;”而不是“gzip_static on”。

location /fd/ { 
    gunzip on; 
    gzip_static always; 
} 

卷曲输出:

$ curl --silent -H "Accept-encoding: gzip" "http://myhost.com/fd/test.txt" | file - 
/dev/stdin: gzip compressed data, from Unix 
$ curl --silent "http://myhost.com/fd/test.txt" | file - 
/dev/stdin: ASCII text