Answer the question
In order to leave comments, you need to log in
Empty variable $proxy_add_x_forwarded_for, nginx 1.2.3
I configure nginx/1.2.3 (debian 6.0.5) as a reverse proxy to tomcat, the config is as follows:
upstream tomcat {
server 127.0.0.1:8080;
}
server {
listen *:80; ## listen for ipv4
sendfile on;
charset utf-8;
server_name test.ru www.test.ru;
access_log /var/log/nginx/test.ru.access.log;
error_log /var/log/nginx/test.ru.error.log;
root /var/www/test.ru/htdocs;
location / {
proxy_pass http://tomcat;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
}
}
......
x-real-ip 92.47.ххх.ххх
connection close
cache-control max-age=0
......
Answer the question
In order to leave comments, you need to log in
In general, I solved the problem, you need to write the following in the tomcat in server.xml (it worked after adding the requestAttributesEnabled="true" attribute to AccessLogValve):
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
...
<Valve className="org.apache.catalina.valves.RemoteIpValve"
remoteIpHeader="X-Forwarded-For"
requestAttributesEnabled="true"
internalProxies="127.0.0.1" />
<Valve className="org.apache.catalina.valves.AccessLogValve"
directory="logs"
prefix="localhost_access_log."
suffix=".log"
requestAttributesEnabled="true"
pattern="%h %l %u %t "%r" %s %b" />
...
</Host>
Why did you decide that the variable is empty and the header is not passed? Look at the same tcpdump, most likely everything is transmitted, just tomcat processes this header as it sees fit.
We go to the off documentation nginx.org/ru/docs/http/ngx_http_proxy_module.html and at the very bottom we read:
$proxy_add_x_forwarded_for
поле заголовка запроса клиента “X-Forwarded-For” и добавленная к нему через запятую переменная $remote_addr. Если же поля “X-Forwarded-For” в заголовке запроса клиента нет, то переменная $proxy_add_x_forwarded_for равна переменной $remote_addr.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question