nginx:gizip_static:似乎不起作用

发布于 2024-12-25 02:52:12 字数 703 浏览 1 评论 0原文

好吧,我的堆栈是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半城柳色半声笛 2025-01-01 02:52:12

我最终想通了这一点。当您运行 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文