From f4ba115e0b0eaecde545e5f37db6aa18917d8f4b Mon Sep 17 00:00:00 2001 From: Hanada Date: Mon, 22 Apr 2024 16:51:49 +0800 Subject: [PATCH 1/2] bugfix: fix module order to avoid taking effect before other modules such as sub filter module (#31) * bugfix: add module order to avoid taking effect before other modules such as sub filter module Module order is incorrect for compression module. For example, if using ngx_http_sub_module, string is not replaced because it it tries to replace content when it is already compressed. For this purpose, you need to add module sorting in config to adjust the order in which modules take effect. --- filter/config | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/filter/config b/filter/config index 1d068e0..2942125 100644 --- a/filter/config +++ b/filter/config @@ -106,5 +106,39 @@ ngx_module_name=ngx_http_zstd_filter_module ngx_module_incs="$ngx_zstd_opt_I" ngx_module_srcs=$HTTP_ZSTD_SRCS ngx_module_libs=$NGX_LD_OPT +ngx_module_order="$ngx_module_name \ + ngx_pagespeed \ + ngx_http_postpone_filter_module \ + ngx_http_ssi_filter_module \ + ngx_http_charset_filter_module \ + ngx_http_xslt_filter_module \ + ngx_http_image_filter_module \ + ngx_http_sub_filter_module \ + ngx_http_addition_filter_module \ + ngx_http_gunzip_filter_module \ + ngx_http_userid_filter_module \ + ngx_http_headers_filter_module \ + ngx_http_copy_filter_module \ + ngx_http_range_body_filter_module \ + ngx_http_not_modified_filter_module \ + ngx_http_slice_filter_module" + . auto/module +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 + next=ngx_http_gzip_filter_module + elif echo $HTTP_FILTER_MODULES | grep pagespeed_etag_filter >/dev/null; then + next=ngx_pagespeed_etag_filter + else + next=ngx_http_range_header_filter_module + fi + + HTTP_FILTER_MODULES=`echo $HTTP_FILTER_MODULES \ + | sed "s/$ngx_module_name//" \ + | sed "s/$next/$next $ngx_module_name/"` +fi + From b4791099149c8cf7d01abb6fbfb1db17410af57a Mon Sep 17 00:00:00 2001 From: Steve Kamerman Date: Fri, 10 Jan 2025 12:24:42 -0500 Subject: [PATCH 2/2] fix: run zstd before brotli if both are enabled --- filter/config | 5 +++-- static/config | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/filter/config b/filter/config index 2942125..3b4af9b 100644 --- a/filter/config +++ b/filter/config @@ -128,8 +128,9 @@ ngx_module_order="$ngx_module_name \ 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 --git a/static/config b/static/config index ed6e66e..505cab0 100644 --- a/static/config +++ b/static/config @@ -107,5 +107,7 @@ ngx_module_type=HTTP 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