3

我有一些网络服务器正在运行,我希望它们都可以通过一个域进行访问。我在 IIS 中将 ARR 设置为另一台服务器中的反向代理,它工作正常。但是,当请求重定向到服务器时,我需要保留源 IP 地址。否则,服务器会看到所有来自本地主机的连接,这不是很好。

我知道有一个选项 forwarded_for 可以创建 X-Forwarded-For 标头,但它并不是真正透明的,因为我有 WAF(Web 应用程序防火墙)问题。

4

3 回答 3

6

Edited:

You need a rewrite rule for each of your websites that are having traffic directed to them from the proxy server. The rule will check to see if the HTTP_X_FORWARDED_FOR header exists and has a value, if it does, then we know the request has been forwarded from the proxy server so we'll set the server variable REMOTE_ADDR to the value of HTTP_X_FORWARDED_FOR because we know that is the true IP address of the user.

Here's the rule:

<rule name="RewriteRemoteAddr">
    <match url="(.*)" />
    <conditions>
        <add input="{HTTP_X_FORWARDED_FOR}" pattern="([_0-9a-zA-Z]+)" />
    </conditions>
    <serverVariables>
        <set name="{REMOTE_ADDR}" value="{HTTP_X_FORWARDED_FOR}" />
    </serverVariables>
    <action type="None" />
</rule>
于 2013-10-16T10:12:14.967 回答
0

您可以使用ARR Helper在日志中获取实际的 Client-IP:

http://blogs.iis.net/anilr/archive/2009/03/03/client-ip-not-logged-on-content-server-when-using-arr.aspx

于 2013-10-23T14:14:07.530 回答
0

我正在使用REMOTE_ADDR上面记录的服务器变量对此进行测试,但它并没有充当完全透明的反向代理:我仍然可以将反向代理和原始 IP 视为原始 IP HTTP_X_FORWARDED_FOR

我完全使用上面的指令:

<set name="REMOTE_ADDR" value="{HTTP_X_FORWARDED_FOR}" replace="true" />
于 2019-08-21T17:54:14.080 回答