diff -ruN a/naxsi_src/naxsi.h b/naxsi_src/naxsi.h --- a/naxsi_src/naxsi.h 2022-09-15 10:40:24.571506605 +0200 +++ b/naxsi_src/naxsi.h 2022-09-15 11:00:20.373150396 +0200 @@ -496,6 +496,17 @@ #define LIBINJ_SQL_T "d:libinj_sql" #define NEGATIVE_T "negative" +#if defined nginx_version && (nginx_version >= 1021005) +// after 1.21.5 NGX_REGEX_MULTILINE is present. +#define NAXSI_REGEX_OPTIONS (NGX_REGEX_CASELESS | NGX_REGEX_MULTILINE) +#else +#if (NGX_PCRE2) +#define NAXSI_REGEX_OPTIONS (PCRE2_CASELESS | PCRE2_MULTILINE) +#else +#define NAXSI_REGEX_OPTIONS (PCRE_CASELESS | PCRE_MULTILINE) +#endif +#endif + /* ** name of hardcoded variables to ** change behavior of naxsi at runtime diff -ruN a/naxsi_src/naxsi_config.c b/naxsi_src/naxsi_config.c --- a/naxsi_src/naxsi_config.c 2022-09-15 10:28:25.718622978 +0200 +++ b/naxsi_src/naxsi_config.c 2022-09-15 11:16:02.981061190 +0200 @@ -322,11 +322,8 @@ custom_rule->target_rx = ngx_pcalloc(r->pool, sizeof(ngx_regex_compile_t)); return_value_if(!custom_rule->target_rx, NGX_CONF_ERROR); -#if (NGX_PCRE2) - custom_rule->target_rx->options = PCRE2_CASELESS | PCRE2_MULTILINE; -#else - custom_rule->target_rx->options = PCRE_CASELESS | PCRE_MULTILINE; -#endif + + custom_rule->target_rx->options = NAXSI_REGEX_OPTIONS; custom_rule->target_rx->pattern = custom_rule->target; custom_rule->target_rx->pool = r->pool; custom_rule->target_rx->err.len = 0; @@ -445,11 +442,8 @@ ha.len = tmp->len - strlen(RX_T); rgc = ngx_pcalloc(r->pool, sizeof(ngx_regex_compile_t)); return_value_if(!rgc, NGX_CONF_ERROR); -#if (NGX_PCRE2) - rgc->options = PCRE2_CASELESS | PCRE2_MULTILINE; -#else - rgc->options = PCRE_CASELESS | PCRE_MULTILINE; -#endif + + rgc->options = NAXSI_REGEX_OPTIONS; rgc->pattern = ha; rgc->pool = r->pool; rgc->err.len = 0; diff -ruN a/naxsi_src/naxsi_utils.c b/naxsi_src/naxsi_utils.c --- a/naxsi_src/naxsi_utils.c 2022-09-15 10:30:01.476347741 +0200 +++ b/naxsi_src/naxsi_utils.c 2022-09-15 11:16:47.700012002 +0200 @@ -800,11 +800,7 @@ ngx_pcalloc(cf->pool, sizeof(ngx_regex_compile_t)); rgc = custloc_array(curr_r->br->custom_locations->elts)[name_idx].target_rx; if (rgc) { -#if (NGX_PCRE2) - rgc->options = PCRE2_CASELESS | PCRE2_MULTILINE; -#else - rgc->options = PCRE_CASELESS | PCRE_MULTILINE; -#endif + rgc->options = NAXSI_REGEX_OPTIONS; rgc->pattern = custloc_array(curr_r->br->custom_locations->elts)[name_idx].target; rgc->pool = cf->pool; rgc->err.len = 0; @@ -820,11 +816,7 @@ ngx_pcalloc(cf->pool, sizeof(ngx_regex_compile_t)); rgc = custloc_array(curr_r->br->custom_locations->elts)[uri_idx].target_rx; if (rgc) { -#if (NGX_PCRE2) - rgc->options = PCRE2_CASELESS | PCRE2_MULTILINE; -#else - rgc->options = PCRE_CASELESS | PCRE_MULTILINE; -#endif + rgc->options = NAXSI_REGEX_OPTIONS; rgc->pattern = custloc_array(curr_r->br->custom_locations->elts)[uri_idx].target; rgc->pool = cf->pool; rgc->err.len = 0;