Preserve Cloudfront brotli compression through a nginx reverse_proxy

My question is similar to Nginx reverse-proxy to a cloudfront distribution and preserve gzip compression but especially regarding the new brotli compression algorithm that is supposed to perform better than gzip in some cases

My AWS Cloudfront Distribution supports brotli

enter image description here

But my website is behind a nginx proxy for various reason, and when proxy_passing the request to cloudfront, I'm losing the brotli compression and I only get gzip.

I have activated gzip compression and gzip_proxied, is there an equivalent that would allow either gzip or brotli compression to be preserved from the cloudfront distribution ? I've heard of brotli modules for nginx and answers of 2017 (example) that mentioned proxy_pass with nginx + brotli wasn't possible, is it still the case ?

server { 
  ...
  gzip on;
  gzip_comp_level 5;
  gzip_min_length 256;
  gzip_proxied any;
  gzip_vary on;
  gzip_types *;

Solution 1:

See this clarification. The ngx_brotli developer mentions that something like brotli_proxied isn't required, as it will compress proxied requests by default.

server { 
  ...
  gzip on;
  gzip_comp_level 5;
  gzip_min_length 256;
  gzip_proxied any;
  gzip_vary on;
  gzip_types *;

  brotli on;
  ...
}

Should be sufficient. If the upstream (Cloudfront, in this case) does/serves Brotli compressed assets, then NGINX will simply pass those back to the client as they are, without doing Brotli compression twice.