Feature #673
Display Real IP Address To Nginx Backend
Description
I use nginx as both a reverse proxy and a web server, each their own server. While examining the log files I found that incoming requests to the backend web server were showing that they were coming from the proxy servers IP address and not from the actual clients IP address.
Proxy Server Frontend¶
- To start edit the proxy config:
vi /usr/local/etc/nginx/proxy.d/www.example.com.conf
- And add the following to the server block:
proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
- And add the following to the server block:
- Then restart nginx:
service nginx restart
Web Server Backend¶
- Recompile nginx with the real IP module:
cd /usr/ports/www/nginx make config make reinstall clean
- Make sure to enable [X]REALIP when configuring nginx
- On the web server backend, edit the server config:
vi /usr/local/etc/nginx/conf.d/www.example.com
- And add the following to the server block:
set_real_ip_from 192.168.100.55; #Upstream proxy server address real_ip_header X-Forwarded-For;
- And add the following to the server block:
Resources¶
Updated by Daniel Curtis about 9 years ago
- Status changed from New to Resolved
- % Done changed from 0 to 100