@@ -28,9 +28,11 @@ http {
28
28
29
29
server {
30
30
# if protocol ~= 'https' then
31
- listen ${http_port};
31
+ listen 127.0.0.1:${http_port};
32
+ listen [::1]:${http_port};
32
33
# else
33
- listen ${http_port} ssl;
34
+ listen 127.0.0.1:${http_port} ssl http2;
35
+ listen [::1]:${http_port} ssl http2;
34
36
ssl_certificate ${cert_path}/kong_spec.crt;
35
37
ssl_certificate_key ${cert_path}/kong_spec.key;
36
38
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
@@ -43,7 +45,12 @@ http {
43
45
location = /healthy {
44
46
access_by_lua_block {
45
47
local host = ngx.req.get_headers()["host"] or "localhost"
46
- host = string.match(host, "[^:]+")
48
+ local host_no_port = ngx.re.match(host, [=[([a-z0-9\-._~%!$&'()*+,;=]+@)?([a-z0-9\-._~%]+|\[[a-z0-9\-._~%!$&'()*+,;=:]+\])(:?[0-9]+)*]=])
49
+ if host_no_port == nil then
50
+ return ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)
51
+ else
52
+ host = host_no_port[2]
53
+ end
47
54
ngx.shared.server_values:set(host .. "_healthy", true)
48
55
ngx.shared.server_values:set(host .. "_timeout", false)
49
56
ngx.log(ngx.INFO, "Host ", host, " is now healthy")
@@ -58,7 +65,12 @@ http {
58
65
location = /unhealthy {
59
66
access_by_lua_block {
60
67
local host = ngx.req.get_headers()["host"] or "localhost"
61
- host = string.match(host, "[^:]+")
68
+ local host_no_port = ngx.re.match(host, [=[([a-z0-9\-._~%!$&'()*+,;=]+@)?([a-z0-9\-._~%]+|\[[a-z0-9\-._~%!$&'()*+,;=:]+\])(:?[0-9]+)*]=])
69
+ if host_no_port == nil then
70
+ return ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)
71
+ else
72
+ host = host_no_port[2]
73
+ end
62
74
ngx.shared.server_values:set(host .. "_healthy", false)
63
75
ngx.log(ngx.INFO, "Host ", host, " is now unhealthy")
64
76
}
@@ -72,7 +84,12 @@ http {
72
84
location = /timeout {
73
85
access_by_lua_block {
74
86
local host = ngx.req.get_headers()["host"] or "localhost"
75
- host = string.match(host, "[^:]+")
87
+ local host_no_port = ngx.re.match(host, [=[([a-z0-9\-._~%!$&'()*+,;=]+@)?([a-z0-9\-._~%]+|\[[a-z0-9\-._~%!$&'()*+,;=:]+\])(:?[0-9]+)*]=])
88
+ if host_no_port == nil then
89
+ return ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)
90
+ else
91
+ host = host_no_port[2]
92
+ end
76
93
ngx.shared.server_values:set(host .. "_timeout", true)
77
94
ngx.log(ngx.INFO, "Host ", host, " is timeouting now")
78
95
}
@@ -86,7 +103,12 @@ http {
86
103
location = /status {
87
104
access_by_lua_block {
88
105
local host = ngx.req.get_headers()["host"] or "localhost"
89
- host = string.match(host, "[^:]+")
106
+ local host_no_port = ngx.re.match(host, [=[([a-z0-9\-._~%!$&'()*+,;=]+@)?([a-z0-9\-._~%]+|\[[a-z0-9\-._~%!$&'()*+,;=:]+\])(:?[0-9]+)*]=])
107
+ if host_no_port == nil then
108
+ return ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)
109
+ else
110
+ host = host_no_port[2]
111
+ end
90
112
local server_values = ngx.shared.server_values
91
113
92
114
local status = server_values:get(host .. "_healthy") and
@@ -109,7 +131,13 @@ http {
109
131
local cjson = require("cjson")
110
132
local server_values = ngx.shared.server_values
111
133
local host = ngx.req.get_headers()["host"] or "localhost"
112
- host = string.match(host, "[^:]+")
134
+ local host_no_port = ngx.re.match(host, [=[([a-z0-9\-._~%!$&'()*+,;=]+@)?([a-z0-9\-._~%]+|\[[a-z0-9\-._~%!$&'()*+,;=:]+\])(:?[0-9]+)*]=])
135
+ ngx.log(ngx.ERR, "host no port: ", require'inspect'(host_no_port))
136
+ if host_no_port == nil then
137
+ return ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)
138
+ else
139
+ host = host_no_port[2]
140
+ end
113
141
local status
114
142
115
143
local status = server_values:get(host .. "_healthy") and
@@ -129,7 +157,8 @@ http {
129
157
}
130
158
# if check_hostname then
131
159
server {
132
- listen ${http_port} default_server;
160
+ listen 127.0.0.1:${http_port} default_server;
161
+ listen [::1]:${http_port} default_server;
133
162
server_name _;
134
163
return 400;
135
164
}
0 commit comments