Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass the remote IP to a proxied service? - Nginx

I'm running a service in localhost at 127.0.01:8000

and I'm proxying this by using:

proxy_pass http://127.0.0.1:8000;

Problem is that I need to pass the user's IP address to the service.


Any ideas?

like image 917
RadiantHex Avatar asked Feb 02 '11 21:02

RadiantHex


2 Answers

I send the real IP to django by setting a custom header:

proxy_set_header X-Real-IP $remote_addr;

Those headers are available in request.META

like image 70
Yuji 'Tomita' Tomita Avatar answered Nov 14 '22 22:11

Yuji 'Tomita' Tomita


See http://wiki.nginx.org/HttpRealIpModule

like image 43
tmc Avatar answered Nov 14 '22 23:11

tmc