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! 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"