Restore Real IP in Nginx Reverse Proxy
Compile Nginx with real ip module. The origin server will then be able to get the real ip address from the proxy server.
Origin Server:
Add the following into conf file. Put it inside server{} but outside location{}.
1 2 3 |
set_real_ip_from 13.124.23.35; real_ip_header X-Forwarded-For; real_ip_recursive on; |
Proxy Server:
1 2 3 4 5 6 7 8 |
location / { proxy_pass https://xxx; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_redirect off; } |
You can further secure the connection by only allowing proxy server to access origin server.
References: