前后端分离项目,最后合并时,第一级是Nginx的反向代理,设置沿用一起的经验,发现后端死活见不到客户的真实ip,都是代理时docker容器的网关ip。后来查阅代理时参数传递的详细说明,是可以设置把哪些信息添加到代理传递环节的。细节不说了,注意下面的位置填上即可。 proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header REMOTE-HOST $remote_addr; 整段的配置实例如下: location / { proxy_pass http://172.17.0.1:3000; 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 REMOTE-HOST $remote_addr; add_header X-Cache $upstream_cache_status; #Set Nginx Cache add_header Cache-Control no-cache; } Last modification:October 22, 2021 © Allow specification reprint Support Appreciate the author AliPayWeChat Like 送杯咖啡,做个交流,谢谢!