Skip to content

Commit

Permalink
feat: add real_ip_recursive to nginx.conf (#4332)
Browse files Browse the repository at this point in the history
  • Loading branch information
keilon authored May 31, 2021
1 parent 7cf52c0 commit 4d60170
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions apisix/cli/ngx_tpl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@ http {
real_ip_header {* http.real_ip_header *};
{% end %}
{% if http.real_ip_recursive then %}
real_ip_recursive {* http.real_ip_recursive *};
{% end %}
{% if real_ip_from then %}
{% print("\nDeprecated: apisix.real_ip_from has been moved to nginx_config.http.real_ip_from. apisix.real_ip_from will be removed in the future version. Please use nginx_config.http.real_ip_from first.\n\n") %}
{% for _, real_ip in ipairs(real_ip_from) do %}
Expand Down
1 change: 1 addition & 0 deletions conf/config-default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ nginx_config: # config for render the template to generate n
send_timeout: 10s # timeout for transmitting a response to the client.then the connection is closed
underscores_in_headers: "on" # default enables the use of underscores in client request header fields
real_ip_header: "X-Real-IP" # http://nginx.org/en/docs/http/ngx_http_realip_module.html#real_ip_header
real_ip_recursive: "off" # http://nginx.org/en/docs/http/ngx_http_realip_module.html#real_ip_recursive
real_ip_from: # http://nginx.org/en/docs/http/ngx_http_realip_module.html#set_real_ip_from
- 127.0.0.1
- 'unix:'
Expand Down
18 changes: 18 additions & 0 deletions t/cli/test_main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -639,3 +639,21 @@ if ! grep "charset gbk;" conf/nginx.conf > /dev/null; then
fi

echo "passed: found the 'charset gbk;' in nginx.conf"

# check realip recursive setting
git checkout conf/config.yaml

echo '
nginx_config:
http:
real_ip_recursive: "on"
' > conf/config.yaml

make init

if ! grep "real_ip_recursive on;" conf/nginx.conf > /dev/null; then
echo "failed: 'real_ip_recursive on;' not in nginx.conf"
exit 1
fi

echo "passed: found 'real_ip_recursive on' in nginx.conf"

0 comments on commit 4d60170

Please sign in to comment.