【发布时间】:2020-02-18 19:31:02
【问题描述】:
我使用 nginx 作为反向代理来处理端口 80 -> 443 重定向,然后到与服务于 drupal (7.69) 站点的 Apache2.4 后端(端口 8182)对话的清漆缓存(端口 8181)。
我已将 nginx 配置为将客户端 IP 转发为:
proxy_pass http://127.0.0.1:8181;
proxy_read_timeout 90;
proxy_connect_timeout 90;
proxy_redirect off;
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 https;
proxy_set_header X-Forwarded-Port 443;
proxy_set_header X-Forwarded-Host $remote_addr;
proxy_set_header Host $host;
我在清漆 vcl_recv 中添加:
if (req.restarts == 0) {
if (req.http.X-Forwarded-For) {
set req.http.X-Forwarded-For =
req.http.X-Forwarded-For + ", " + client.ip;
} else {
set req.http.X-Forwarded-For = client.ip;
}
}
在 apache 中我已经安装了 remoteip 模块并设置了以下配置:
RemoteIPHeader X-Forwarded-For
RemoteIPTrustedProxy 127.0.0.1
在drupal的settings.php中我有
$conf['reverse_proxy'] = True;
$conf['reverse_proxy_header'] = 'X-Forwarded-For';
$conf['reverse_proxy_addresses'] = array('127.0.0.1');
...但是,drupal 似乎仍然只看到和登录 localhost (127.0.0.1) ip,而不是真正的客户端 IP。因此,表单被记录为不是来自真正的用户,而是来自服务器本身。
我想知道我的 varnish 配置是否已关闭,因为我还从 nginx 代理并绕过 varnish 直接进入绕过 drupal(它是 SMF)但在相同的 apache 配置上运行的论坛;论坛正在记录从 nginx 发送的客户端 IP(使用相同的标头更改和 apache remoteip 配置)就好了。
非常感谢您的指导/建议。
【问题讨论】:
标签: drupal-7 varnish nginx-reverse-proxy apache2.4