This is an automated email from the ASF dual-hosted git repository.

membphis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git


The following commit(s) were added to refs/heads/master by this push:
     new 83ab543  fix: use the builtin server by default (#3907)
83ab543 is described below

commit 83ab5439a03ebff133a36045b8e9cc3003b8baf0
Author: 罗泽轩 <[email protected]>
AuthorDate: Thu Mar 25 23:49:38 2021 +0800

    fix: use the builtin server by default (#3907)
    
    Fix #3906
---
 apisix/cli/ngx_tpl.lua |  14 +++---
 t/cli/test_main.sh     |  69 ---------------------------
 t/cli/test_snippet.sh  | 123 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 131 insertions(+), 75 deletions(-)

diff --git a/apisix/cli/ngx_tpl.lua b/apisix/cli/ngx_tpl.lua
index 2bfa582..00cda09 100644
--- a/apisix/cli/ngx_tpl.lua
+++ b/apisix/cli/ngx_tpl.lua
@@ -345,31 +345,33 @@ http {
 
     server {
         {% for _, item in ipairs(node_listen) do %}
-        listen {* item.port *} {% if enable_reuseport then %} reuseport {% end 
%} {% if item.enable_http2 then %} http2 {% end %};
+        listen {* item.port *} default_server {% if enable_reuseport then %} 
reuseport {% end %} {% if item.enable_http2 then %} http2 {% end %};
         {% end %}
         {% if ssl.enable then %}
         {% for _, port in ipairs(ssl.listen_port) do %}
-        listen {* port *} ssl {% if ssl.enable_http2 then %} http2 {% end %} 
{% if enable_reuseport then %} reuseport {% end %};
+        listen {* port *} ssl default_server {% if ssl.enable_http2 then %} 
http2 {% end %} {% if enable_reuseport then %} reuseport {% end %};
         {% end %}
         {% end %}
         {% if proxy_protocol and proxy_protocol.listen_http_port then %}
-        listen {* proxy_protocol.listen_http_port *} proxy_protocol;
+        listen {* proxy_protocol.listen_http_port *} default_server 
proxy_protocol;
         {% end %}
         {% if proxy_protocol and proxy_protocol.listen_https_port then %}
-        listen {* proxy_protocol.listen_https_port *} ssl {% if 
ssl.enable_http2 then %} http2 {% end %} proxy_protocol;
+        listen {* proxy_protocol.listen_https_port *} ssl default_server {% if 
ssl.enable_http2 then %} http2 {% end %} proxy_protocol;
         {% end %}
 
         {% if enable_ipv6 then %}
         {% for _, item in ipairs(node_listen) do %}
-        listen [::]:{* item.port *} {% if enable_reuseport then %} reuseport 
{% end %} {% if item.enable_http2 then %} http2 {% end %};
+        listen [::]:{* item.port *} default_server {% if enable_reuseport then 
%} reuseport {% end %} {% if item.enable_http2 then %} http2 {% end %};
         {% end %}
         {% if ssl.enable then %}
         {% for _, port in ipairs(ssl.listen_port) do %}
-        listen [::]:{* port *} ssl {% if ssl.enable_http2 then %} http2 {% end 
%} {% if enable_reuseport then %} reuseport {% end %};
+        listen [::]:{* port *} ssl default_server {% if ssl.enable_http2 then 
%} http2 {% end %} {% if enable_reuseport then %} reuseport {% end %};
         {% end %}
         {% end %}
         {% end %} {% -- if enable_ipv6 %}
 
+        server_name _;
+
         {% if ssl.ssl_trusted_certificate ~= nil then %}
         lua_ssl_trusted_certificate {* ssl.ssl_trusted_certificate *};
         {% end %}
diff --git a/t/cli/test_main.sh b/t/cli/test_main.sh
index ca287bb..e2dc488 100755
--- a/t/cli/test_main.sh
+++ b/t/cli/test_main.sh
@@ -481,75 +481,6 @@ fi
 
 echo "passed: found 'my_dict' in nginx.conf"
 
-# allow injecting configuration snippets
-
-echo '
-apisix:
-    node_listen: 9080
-    enable_admin: true
-    port_admin: 9180
-    stream_proxy:
-        tcp:
-            - 9100
-nginx_config:
-    main_configuration_snippet: |
-        daemon on;
-    http_configuration_snippet: |
-        chunked_transfer_encoding on;
-    http_server_configuration_snippet: |
-        set $my "var";
-    http_admin_configuration_snippet: |
-        log_format admin "$request_time $pipe";
-    http_end_configuration_snippet: |
-        server_names_hash_bucket_size 128;
-    stream_configuration_snippet: |
-        tcp_nodelay off;
-' > conf/config.yaml
-
-make init
-
-grep "daemon on;" -A 2 conf/nginx.conf | grep "configuration snippet ends" > 
/dev/null
-if [ ! $? -eq 0 ]; then
-    echo "failed: can't inject main configuration"
-    exit 1
-fi
-
-grep "chunked_transfer_encoding on;" -A 2 conf/nginx.conf | grep 
"configuration snippet ends" > /dev/null
-if [ ! $? -eq 0 ]; then
-    echo "failed: can't inject http configuration"
-    exit 1
-fi
-
-grep 'set $my "var";' -A 2 conf/nginx.conf | grep "configuration snippet ends" 
> /dev/null
-if [ ! $? -eq 0 ]; then
-    echo "failed: can't inject http server 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"
-    exit 1
-fi
-
-grep 'server_names_hash_bucket_size 128;' -A 2 conf/nginx.conf | grep 
"configuration snippet ends" > /dev/null
-if [ ! $? -eq 0 ]; then
-    echo "failed: can't inject http end configuration"
-    exit 1
-fi
-
-grep 'server_names_hash_bucket_size 128;' -A 3 conf/nginx.conf | grep "}" > 
/dev/null
-if [ ! $? -eq 0 ]; then
-    echo "failed: can't inject http end configuration"
-    exit 1
-fi
-
-grep 'tcp_nodelay off;' -A 2 conf/nginx.conf | grep "configuration snippet 
ends" > /dev/null
-if [ ! $? -eq 0 ]; then
-    echo "failed: can't inject stream configuration"
-    exit 1
-fi
-
 # check disable cpu affinity
 git checkout conf/config.yaml
 
diff --git a/t/cli/test_snippet.sh b/t/cli/test_snippet.sh
new file mode 100755
index 0000000..8a383c9
--- /dev/null
+++ b/t/cli/test_snippet.sh
@@ -0,0 +1,123 @@
+#!/usr/bin/env bash
+
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+. ./t/cli/common.sh
+
+# allow injecting configuration snippets
+
+echo '
+apisix:
+    node_listen: 9080
+    enable_admin: true
+    port_admin: 9180
+    stream_proxy:
+        tcp:
+            - 9100
+nginx_config:
+    main_configuration_snippet: |
+        daemon on;
+    http_configuration_snippet: |
+        chunked_transfer_encoding on;
+    http_server_configuration_snippet: |
+        set $my "var";
+    http_admin_configuration_snippet: |
+        log_format admin "$request_time $pipe";
+    http_end_configuration_snippet: |
+        server_names_hash_bucket_size 128;
+    stream_configuration_snippet: |
+        tcp_nodelay off;
+' > conf/config.yaml
+
+make init
+
+grep "daemon on;" -A 2 conf/nginx.conf | grep "configuration snippet ends" > 
/dev/null
+if [ ! $? -eq 0 ]; then
+    echo "failed: can't inject main configuration"
+    exit 1
+fi
+
+grep "chunked_transfer_encoding on;" -A 2 conf/nginx.conf | grep 
"configuration snippet ends" > /dev/null
+if [ ! $? -eq 0 ]; then
+    echo "failed: can't inject http configuration"
+    exit 1
+fi
+
+grep 'set $my "var";' -A 2 conf/nginx.conf | grep "configuration snippet ends" 
> /dev/null
+if [ ! $? -eq 0 ]; then
+    echo "failed: can't inject http server 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"
+    exit 1
+fi
+
+grep 'server_names_hash_bucket_size 128;' -A 2 conf/nginx.conf | grep 
"configuration snippet ends" > /dev/null
+if [ ! $? -eq 0 ]; then
+    echo "failed: can't inject http end configuration"
+    exit 1
+fi
+
+grep 'server_names_hash_bucket_size 128;' -A 3 conf/nginx.conf | grep "}" > 
/dev/null
+if [ ! $? -eq 0 ]; then
+    echo "failed: can't inject http end configuration"
+    exit 1
+fi
+
+grep 'tcp_nodelay off;' -A 2 conf/nginx.conf | grep "configuration snippet 
ends" > /dev/null
+if [ ! $? -eq 0 ]; then
+    echo "failed: can't inject stream configuration"
+    exit 1
+fi
+
+# use the builtin server by default
+
+echo '
+apisix:
+    node_listen: 9080
+nginx_config:
+    http_configuration_snippet: |
+        server {
+            listen 9080;
+            server_name qa.com www.qa.com;
+            location / {
+                return 503 "ouch";
+            }
+        }
+' > conf/config.yaml
+
+make run
+
+sleep 1
+code=$(curl -k -i -o /dev/null -s -w %{http_code} http://127.0.0.1:9080 -H 
'Host: m.qa.com')
+if [ ! $code -eq 404 ]; then
+    echo "failed: use the builtin server by default"
+    exit 1
+fi
+code=$(curl -k -i -o /dev/null -s -w %{http_code} http://127.0.0.1:9080 -H 
'Host: www.qa.com')
+if [ ! $code -eq 503 ]; then
+    echo "failed: use the builtin server by default"
+    exit 1
+fi
+
+make stop
+
+echo "passed: use the builtin server by default"

Reply via email to