From 6168cb4681734d0b6934cd30d31dce69419ec868 Mon Sep 17 00:00:00 2001 From: lunhaiz Date: Wed, 8 Dec 2021 15:12:12 +0800 Subject: [PATCH 1/2] feat: http_server_location_configuration_snippet configuration --- apisix/cli/ngx_tpl.lua | 6 ++++++ conf/config-default.yaml | 3 +++ 2 files changed, 9 insertions(+) diff --git a/apisix/cli/ngx_tpl.lua b/apisix/cli/ngx_tpl.lua index f5fa5d6ee06d..523ae4d7ef76 100644 --- a/apisix/cli/ngx_tpl.lua +++ b/apisix/cli/ngx_tpl.lua @@ -573,6 +573,12 @@ http { set $ctx_ref ''; set $from_error_page ''; + # http server location configuration snippet starts + {% if http_server_location_configuration_snippet then %} + {* http_server_location_configuration_snippet *} + {% end %} + # http server location configuration snippet ends + {% if enabled_plugins["dubbo-proxy"] then %} set $dubbo_service_name ''; set $dubbo_service_version ''; diff --git a/conf/config-default.yaml b/conf/config-default.yaml index 7be15f9267b0..3d089bdbf052 100644 --- a/conf/config-default.yaml +++ b/conf/config-default.yaml @@ -191,6 +191,9 @@ nginx_config: # config for render the template to generate n http_server_configuration_snippet: | # Add custom Nginx http server configuration to nginx.conf. # The configuration should be well indented! + http_server_location_configuration_snippet: | + # Add custom Nginx http server location configuration to nginx.conf. + # The configuration should be well indented! http_admin_configuration_snippet: | # Add custom Nginx admin server configuration to nginx.conf. # The configuration should be well indented! From 027f9111f629fab1568ca20bec26e4b9ecdedcc3 Mon Sep 17 00:00:00 2001 From: lunhaiz Date: Wed, 8 Dec 2021 17:28:11 +0800 Subject: [PATCH 2/2] http_server_location_configuration_snippet test --- t/cli/test_snippet.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/t/cli/test_snippet.sh b/t/cli/test_snippet.sh index e103224236f5..0684d6c1f659 100755 --- a/t/cli/test_snippet.sh +++ b/t/cli/test_snippet.sh @@ -37,6 +37,8 @@ nginx_config: chunked_transfer_encoding on; http_server_configuration_snippet: | set $my "var"; + http_server_location_configuration_snippet: | + set $upstream_name -; http_admin_configuration_snippet: | log_format admin "$request_time $pipe"; http_end_configuration_snippet: | @@ -65,6 +67,12 @@ if [ ! $? -eq 0 ]; then exit 1 fi +grep 'set $upstream_name -;' -A 2 conf/nginx.conf | grep "configuration snippet ends" > /dev/null +if [ ! $? -eq 0 ]; then + echo "failed: can't inject http server location configuration" + exit 1 +fi + grep 'log_format admin "$request_time $pipe";' -A 2 conf/nginx.conf | grep "configuration snippet ends" > /dev/null if [ ! $? -eq 0 ]; then echo "failed: can't inject admin server configuration"