nginx与tomcat环境中获取真实IP的办法
时间:2014-06-19 02:37 来源:linux.it.net.cn 作者:IT网
第一步:在nginx.conf中配置反向代理时把真实IP带上,例如:
server {
listen 80;
server_name boyan.com;
location ~ ^/(WEB-INF)/ {
deny all;
}
location / {
proxy_pass http://localhost:8888;
proxy_set_header X-Real-IP $remote_addr;
}
}
第二步:应用程序中用 String ip = request.getHeader("X-Real-IP");替代String ip = request.getRemoteAddr();即可
注:
和Apache有点类似
X-Forwarded-For
WL-Proxy-Client-IP
(责任编辑:IT)
第一步:在nginx.conf中配置反向代理时把真实IP带上,例如:
location / { 第二步:应用程序中用 String ip = request.getHeader("X-Real-IP");替代String ip = request.getRemoteAddr();即可
注:
|