2

nginx 是在启用 Brotli 的情况下编译的。在我的 nginx.conf

http {
    ...
    brotli_static on;
}

我的 .br 文件位于带有proxy_pass.

location / {
    ...
    proxy_pass http://app;
}

并且 .br 文件已在该app服务器上生成:

$ ls -lh public/js/dist/index.js*
-rw-r--r-- 1 mike wheel 1.2M Apr  4 09:07 public/js/dist/index.js
-rw-r--r-- 1 mike wheel 201K Apr  4 09:07 public/js/dist/index.js.br

拉下未压缩文件的工作原理:

wget https://example.com/js/dist/index.js

拉下 1,157,704 大小的未压缩文件。

wget -S --header="accept-encoding: gzip" https://example.com/js/dist/index.js

拉下一个 309,360 大小的 gzip 文件。

但:

wget -S --header="accept-encoding: br" https://example.com/js/dist/index.js

仍然获得完整的 1,157,704 大小的未压缩文件。

我曾希望 brotli_static也能代理 .br 文件请求 - 向后端发送 GET 请求以获取 .br 等效资源 - 但这似乎不起作用。

brotli_static 可以通过 proxy_pass 工作吗?

4

2 回答 2

2

基于Maxim Dounin(nginx 核心工程师)对 gzip_static 的评论——我认为 brotli_static 的行为类似于——brotli_static 只处理文件,而不是 HTTP 资源:

也就是说, gzip_static 仅在 nginx 即将返回常规文件时才起作用。

所以看起来 brotli_static 和 proxy_pass 是不可能的。

于 2017-04-04T12:13:01.337 回答
0

您的 nginx 配置文件需要一个部分来告诉它为静态内容文件夹提供服务。您不希望您的应用服务器这样做。

我相信你需要把它放在前面,location /以便它优先。

于 2017-04-07T21:53:13.617 回答