使用SSH内网穿透加Nginx反向代理之后获取真实IP

配置Nginx

1
2
3
4
5
6
7
8
9
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
# try_files $uri $uri/ =404;
proxy_pass http://localhost:8080;

proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
}

重新加载Nginx配置:

1
nginx -s reload

JAVA获取IP

1
String ip = request.getHeader("X-Real-IP");