时间:2021-07-01 10:21:17 帮助过:9人阅读
nginx端配置文件/etc/nginx/conf.d/default.conf
server {
listen 80;
server_name localhost;
location /{
rewrite ^/web(.*)$ /$1 last;
proxy_pass http://localhost:8080/web/;
proxy_cookie_path /web /;
#以下三个proxy_set_header配置项是重点
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}tomcat日志配置文件$CATALINA_HOME/conf/server.xml
在host中,修改以下内容
其中X-Real-IP与NGINX中配置的要对应,此变量即是客户的真实IP,pattern的其它参数,请参考官方:http://tomcat.apache.org/tomcat-7.0-doc/config/valve.html#Access_Logging
以上就介绍了 nginx前端,tomcat后端服务器获取客户的真实IP,包括tomcat访问日志获取真实IP的配置,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。