nginxproxybrotlingx-brotli

How can I use nginx brotli_static with proxy_pass?


nginx is compiled with Brotli enabled. In my nginx.conf

http {
    ...
    brotli_static on;
}

My .br files are located on a server with proxy_pass.

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

And .br files have been generated on that app server:

$ 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

Pulling down the uncompressed file works:

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

Pulls down 1,157,704 size uncompressed file.

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

Pulls down a 309,360 size gzipped file.

But:

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

Still gets the full 1,157,704 size uncompressed file.

I had hoped brotli_static would proxy the .br file requests too - sending something a GET request to the backend for the .br equivalent resource - but this doesn't seem to work.

Can brotli_static work through proxy_pass?


Solution

  • Based on Maxim Dounin (an nginx core engineer)'s comment on gzip_static - which I imagine brotli_static behaves similarly to - brotli_static only handles files, not HTTP resources:

    That is, gzip_static is only expected to work when nginx is about to return regular files.

    So it looks like brotli_static and proxy_pass isn't possible.