tokers / zstd-nginx-module

Nginx modules for the Zstandard compression
BSD 2-Clause "Simplified" License
196 stars 23 forks source link

brotli_static and zstd_static Wrong Module order #40

Open mklooss opened 4 days ago

mklooss commented 4 days ago

i am currently struggle to get "zstd_static on" and "brotli_static on", because Webkit does not Support zstd.

zstd_filter works as expected

Build:

./configure --add-module=zstd-nginx-module-master --add-module=ngx_brotli-master

Result:

$ curl -v -k -H 'Accept-Encoding: gzip, deflate, br, zstd' https://172.17.0.2/test.css
> GET /test.css HTTP/1.1
> Host: 172.17.0.2
> User-Agent: curl/8.5.0
> Accept: */*
> Accept-Encoding: gzip, deflate, br, zstd
> 
< HTTP/1.1 200 OK
< Server: nginx/1.26.2
< Date: Wed, 20 Nov 2024 20:15:21 GMT
< Content-Type: text/css
< Content-Length: 30
< Last-Modified: Wed, 20 Nov 2024 19:33:50 GMT
< Connection: keep-alive
< Vary: Accept-Encoding
< ETag: "673e399e-1e"
< Content-Encoding: br
mklooss commented 4 days ago

Okay, found an workaround for me:

had to reorder the module list, so i have to first define brotli and then zstd in configure task:

./configure --add-module=ngx_brotli-master --add-module=zstd-nginx-module-master

and the this patch for zstd

diff -u -r a/filter/config b/filter/config
--- a/filter/config        2024-11-20 19:20:15.000000000 +0000
+++ b/filter/config   2024-11-20 20:49:50.419587235 +0000
@@ -128,8 +128,9 @@
 if [ "$ngx_module_link" != DYNAMIC ]; then
     # ngx_module_order doesn't work with static modules,
     # so we must re-order filters here.
-
-    if [ "$HTTP_GZIP" = YES ]; then
+    if echo $HTTP_FILTER_MODULES | grep ngx_http_brotli_filter_module >/dev/null; then
+        next=ngx_http_brotli_filter_module
+    elif [ "$HTTP_GZIP" = YES ]; then
         next=ngx_http_gzip_filter_module
     elif echo $HTTP_FILTER_MODULES | grep pagespeed_etag_filter >/dev/null; then
         next=ngx_pagespeed_etag_filter
diff -u -r a/static/config b/static/config
--- a/static/config        2024-11-20 19:20:15.000000000 +0000
+++ b/static/config   2024-11-20 20:29:15.728061021 +0000
@@ -107,5 +107,7 @@
 ngx_module_name=ngx_http_zstd_static_module
 ngx_module_incs="$ngx_zstd_opt_I"
 ngx_module_srcs=$HTTP_ZSTD_SRCS
+ngx_module_order="ngx_http_brotli_static_module \
+                  $ngx_module_name"

 . auto/module