-
Notifications
You must be signed in to change notification settings - Fork 141
在spring boot项目和nginx结合时获取真实IP
GeXiangDong edited this page Jan 21, 2023
·
6 revisions
location / {
proxy_pass http://127.0.0.1:8008/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_redirect off;
}
修改application.yml
spring boot 2.3 及以后
server:
forward-headers-strategy: NATIVE
tomcat:
remoteip:
remote-ip-header: X-Real-IP
protocol-header: X-Forwarded-Proto
2.3之前版本
server:
tomcat:
remote-ip-header: X-Real-IP
protocol-header: X-Forwarded-Proto
之后在程序中获取的IP就是真实的IP地址了。