简体   繁体   English

有什么办法可以在Nginx反向代理上获取真实的客户端IP地址,而无需在服务器端进行任何更改

[英]Is There Any Ways to Get the Real Client IP Address on Nginx Reverse proxy Without Changing any things on server side

I set a server 130.153.32.231 (Nginx) as a reverse_proxy for www.mysite.com (Apache) they both had separate server, The problem was how can I get the user real IP address that access 130.153.32.231 and pass it to www.mysite.com without changing anythings in www.mysite.com, because what I can see all user shows 130.153.32.231 not the real IP. 我将服务器130.153.32.231(Nginx)设置为www.mysite.com (Apache)的反向代理,它们都有单独的服务器,问题是如何获取访问130.153.32.231的用户真实IP地址并将其传递给www .mysite.com,而无需更改www.mysite.com中的任何内容,因为我看到的所有用户都显示130.153.32.231不是真正的IP。

Already try http_realip_module and proxy_set_header X-Forwarded-For but none of this do the job, any ones know how to fix this.. 已经尝试使用http_realip_module和proxy_set_header X-Forwarded-For,但是这些都无法完成,任何人都知道如何解决。

On the nginx side make sure you are passing through the remote address to the X-Forwarded-For header using something like: 在Nginx端,请确保使用以下方式将远程地址传递到X-Forwarded-For标头:

proxy_set_header X-Forwarded-For $remote_addr

Then on the Apache side use mod_remoteip ( docs here ) to take the IP address from the X-Forwarded-For header: 然后在Apache端使用mod_remoteip( docs此处 )从X-Forwarded-For标头获取IP地址:

RemoteIPInternalProxy 130.153.32.231
RemoteIPHeader X-Forwarded-For

You also need to tell Apache to trust the proxy (the RemoteIPInternalProxy does this). 您还需要告诉Apache信任代理(RemoteIPInternalProxy会这样做)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 Nginx 作为反向代理在 gRPC Java 服务器端获取真实的客户端 IP - How to get real client IP on gRPC Java server side using Nginx as reverse proxy 如何在nginx代理后面的金字塔服务器中获取客户端的真实IP - How to get the real IP of a client in a pyramid server behind a nginx proxy 用 Rails 和 Nginx 获取客户端的真实 IP 地址? - Get the real IP address of client with Rails and Nginx? 使用 Nginx 反向代理时无法获取客户端的真实 IP - Can't get client's real IP when using Nginx reverse proxy nginx反向代理发送客户端IP而不是服务器IP - nginx reverse-proxy sending client IP instead of server IP Ghost如何从Nginx(反向代理)获取真实IP? - How does ghost get real IP from nginx(reverse proxy)? 如何在 Nginx 服务器上获取客户端真正的 ip - How to get client real ip on Nginx server Dokku-获取容器内Nginx反向代理的IP地址? - Dokku - get ip address of nginx reverse proxy inside container? haproxy 背后的 nginx 邮件代理 - 获取客户端的真实 IP 地址 - nginx mail proxy behind haproxy - get clients real ip address nginx 反向代理重定向到内部 ip 地址 - nginx reverse proxy redirects to internal ip address
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM