Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add real_ip_recursive to nginx.conf #4332

Merged
merged 5 commits into from
May 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 *};
keilon marked this conversation as resolved.
Show resolved Hide resolved
{% 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"