重定向请求 IP 的 Nginx 在杂志中 Apache

我用 nginx 作为外部反向代理 Apache, 我有里面 nginx 以下配置:

location / {
if (-f $request_filename) {
add_header X-Static hit;
access_log off;
}

if (!-f $request_filename) {
proxy_pass [url=https://127.0.0.1:8000;]https://127.0.0.1:8000;[/url]
add_header X-Static miss;
}

从 apache, 倾听港口 8000 在本地。 当我观看杂志 apache, 所有请求来自地址 127.0.0.1:443 (哪里 nginx). 我想重定向真实的IP地址 apache, 因此,他主要在杂志中保留它。

我试图在位置块中添加以下行,但无用

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

我在这里错过了一步吗? 我需要更改日志格式 apache? 目前,使用组合的默认杂志。
已邀请:

小姐请别说爱

赞同来自:

您需要更改日志格式 apache 为了支持 x-forward

例如

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %{X-Forwarded-For}i" combined

然后你可以使用

 CustomLog logs/access_log combined

因此,您杂志中的最后一个条目将继续 nginx 为真的套装 IP. 当然,您可以更改字符串中的顺序。 LogFormat.

帅驴

赞同来自:

看一看
http://stderr.net/apache/rpaf/
在 deb / ubuntu 您可以设置包名称 libapache2-mod-rpaf

安装后,添加IP地址。 nginx 在参数中 RPAFproxy_ips 在 /etc/apache2/mods-available/rpaf.conf

<ifmodule mod_rpaf.c="">
RPAFenable On RPAFsethostname
On RPAFproxy_ips 127.0.0.1
</ifmodule>

重新开始 apache, 您应该看到杂志中的正确IP地址。

我会在你的配置中保存它 nginx:

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

君笑尘

赞同来自:

您只更改了HTTP标题,而不是如何 Apache 看到连接 (经过 Nginx).

要回复问题请先登录注册