【问题标题】:how to make nginx and apache work together for showing the real client IP?如何让 nginx 和 apache 一起工作以显示真实的客户端 IP?
【发布时间】:2012-02-19 15:32:51
【问题描述】:

我正在尝试在 nginx 代理后面配置 apache 服务器。 nginx 和 apache 实例位于两个不同的主机上。 两台服务器都在运行 debian 挤压。

我在前端服务器(192.168.1.30)的nginx.conf中有这个

 server {

    listen   80; ## listen for ipv4
    listen   [::]:80 default ipv6only=on; ## listen for ipv6

    server_name  front.tld.org;  #real hostname changed

    access_log  /var/log/nginx/localhost.access.log;

    proxy_set_header   Host             $host;
    proxy_set_header   X-Real-IP        $remote_addr;
    proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;

    location / {
      proxy_pass http://192.168.1.1:80;  #local IP of the server running apache
    }

在apache主机(192.168.1.1)上,/etc/apache2/mods-enabled/rpaf.conf

<IfModule mod_rpaf.c>
RPAFenable On
RPAFsethostname On
RPAFproxy_ips 192.168.1.30
RPAFheader X-Real-IP
</IfModule>

我重新启动了 nginx 和 apache2 服务。 但是在 apache2 /var/log/apache2/access.log 中,我总是有一个来自 192.168.1.30 (代理)而不是真实客户端的原始 IP。

有什么问题吗?知道如何调试吗?

【问题讨论】:

    标签: apache proxy nginx


    【解决方案1】:

    你现在看到的是正确的行为。因为只有您的应用程序(在 Apache 上运行)才能看到真实 IP。例如,安装 WordPress 等示例应用程序并安装 Piwik 等实时分析。在 WordPress 页脚中插入 Piwik 代码并访问您的 WordPress 站点(注销后)。现在 Piwik 将显示真实 IP,而不是 RPAFproxy_ips 中设置的 IP。

    【讨论】:

      【解决方案2】:

      作为记录,Debian 挤压配置文件有些奇怪。

      以下配置有效:

      RPAFenable On
      RPAFsethostname On
      RPAFproxy_ips 172.27.6.74 172.27.7.17 127.0.0.1 ::1
      RPAFheader X-Forwarded-For
      

      (我不得不删除&lt;IfModule mod_rpaf.c&gt;

      【讨论】:

      • 可以确认此问题已解决,谢谢:)
      猜你喜欢
      • 2016-12-05
      • 2015-06-29
      • 2019-01-01
      • 2020-10-01
      • 2011-09-02
      • 1970-01-01
      • 1970-01-01
      • 2020-08-23
      • 1970-01-01
      相关资源
      最近更新 更多