nginx:gizip_static:似乎不起作用
好吧,我的堆栈是 Ubuntu、Nginx 1 和 Unicorn。我想让 Nginx 提供静态内容的预编译 gzip。
相关的nginx配置:
location ~ ^/assets/ {
gzip_static on;
gzip_http_version 1.1;
gzip_proxied expired no-cache no-store private auth;
gzip_disable "MSIE [1-6]\.";
gzip_vary on;
expires 24h;
add_header Cache-Control public;
}
然后从另一个sf问题我运行strace来查看它们是否被请求,结果:
open("/media/sf_ape/public/assets/application-ae30e133eabbb10d9464189d3fb71e25.js.gz", O_RDONLY|O_NONBLOCK|O_LARGEFILE) = 9
我已经验证了这个文件存在。但是,当我查看访问日志时,它提供的是常规 .js 文件,而不是 .gz 文件。我已经验证请求的标头指定了 gzip,并且响应标头现在显示 gzip。我已经用谷歌搜索了很多,但到目前为止我还没有找到我的问题的答案。我可能在某个地方错过了它,但任何帮助将不胜感激。
Ok my stack is Ubuntu, Nginx 1, and Unicorn. I want to have Nginx serve precompiled gzips of static content.
relevant nginx config:
location ~ ^/assets/ {
gzip_static on;
gzip_http_version 1.1;
gzip_proxied expired no-cache no-store private auth;
gzip_disable "MSIE [1-6]\.";
gzip_vary on;
expires 24h;
add_header Cache-Control public;
}
then from another sf question I ran strace to see if they were being requested, the results:
open("/media/sf_ape/public/assets/application-ae30e133eabbb10d9464189d3fb71e25.js.gz", O_RDONLY|O_NONBLOCK|O_LARGEFILE) = 9
I have verified this file exists. However, when I watch the access log it delivers the regular .js file not the .gz one. I have verified that the requested header specifies gzip, and that the response header is showing now gzip. I've googled quite a bit, but I haven't found an answer to my problem so far. I could have missed it somewhere, but any help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最终想通了这一点。当您运行 rake asset:precompile 时,所有静态资源都会被编译并移动到 /public。例如,技巧是 .js 和 .js.gz 具有完全相同的时间戳。一旦我触摸了 *.gz,一切就正常了。希望这可以节省某人一些时间。
I figured this out eventually. When you run rake assets:precompile all the static assets are compiled and moved to /public. The trick is for example that the .js and the .js.gz have the exact same timestamp. Once I did touch *.gz everything served correctly. Hope that saves someone some time.