Answer the question
In order to leave comments, you need to log in
Nginx incorrectly proxying x-real-ip?
There is an nginx config that looks something like this.
The problem is that for some reason nginx does not proxy real-ip to the backend. Or rather, it proxies, but instead of real ip - ip of the server.
server {<br>
<br>
listen 80;<br>
<br>
proxy_set_header X-Real-IP $remote_addr;<br>
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;<br>
proxy_set_header X-NginX-Proxy true;<br>
proxy_redirect off;<br>
<br>
location / {<br>
<br>
if ($request_uri ~* "/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)" ) {<br>
set $shard $1;<br>
set $hash $2;<br>
}<br>
<br>
if ($shard = '5a5dc35b') {<br>
proxy_pass http://176.9.22.27/code/$2;<br>
}<br>
}<br>
}<br>
{ 'x-real-ip': '188.40.116.158',<br>
'x-forwarded-for': '80.235.55.211, 188.40.116.158',<br>
host: '176.9.22.27',<br>
'x-nginx-proxy': 'true',<br>
connection: 'close',<br>
'cache-control': 'max-age=0',<br>
'user-agent': 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.79 Safari/535.11',<br>
accept: '*/*',<br>
'accept-encoding': 'gzip,deflate,sdch',<br>
'accept-language': 'en-US,en;q=0.8',<br>
'accept-charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3' }<br>
Answer the question
In order to leave comments, you need to log in
Variable description:
$proxy_add_x_forwarded_for
client request header field “X-Forwarded-For” and $remote_addr variable added to it separated by commas. If there is no “X-Forwarded-For” field in the client request header, then the $proxy_add_x_forwarded_for variable is equal to the $remote_addr variable.
There is a double proxy here. Show the full nginx config.
nginx.org/ru/docs/http/ngx_http_realip_module.html
I added to help on the backend:
set_real_ip_from 10.0.3.1; // address of the proxying host
real_ip_header X-Real-IP;
real_ip_recursive on;
and try to write the proxy_set_header directives directly next to the proxy_pass
Please help (not enough karma for a new question).
There is nginx + apache + rpaf. When accessing nginx, it writes ip local. When accessing apache directly on port 8080, the user's ip is written. Typical config.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question