Symptoms
- Brotli is not being used to compress content even if the Plesk version is already 18.0.33 and higer and Gzip is being used instead
- Nginx is configured in Proxy mode
Cause
This behavior is expected.
Apache serves static file requests before Nginx and Apache uses gzip to encode responses.
After that, Nginx receives these responses to resend them to the user already encoded with gzip. As a result, the Nginx Brotli module doesn't try to compress these files.
Resolution
You can find a comment about it in ngx-brotli source code:
Brotli and GZip modules never stack, i.e. when one of them sets
"Content-Encoding" the other becomes a pass-through filter. Consequently,
it is almost legal to reuse this "buffered" bit.
IIUC, buffered == some data passed to filter has not been pushed further.
The following working scheme is used by default:
- Nginx receives an HTTP request to a static file.
- Nginx makes a proxy request to Apache.
- If some Apache module is processing requests, Apache just makes a response and uses gzip encoding.
- If none of Apache modules make a request processing,
mod_aclr
tells Nginx that it can respond by itself. In this case, Nginx makes a response and uses Brotli encoding.
To avoid this behavior Nginx can be forced to answer any requests for a site's static resources without a call to Apache:
- Enable the checkbox "Serve static files directly by Nginx'' in Domains >example.com >Apache & Nginx Settings>Nginx settings.
The other workarounds could be:
-
Setup the
SetEnv no-gzip 1
value in the Additional Apache directives of Domains >example.com >Apache & Nginx Settings. -
Or either one of the following ones:
- Do a2dismod deflate
- Disable deflate on the specific domain
- Disable Proxy mode
- Disable Brotli in Apache