0

再会,

下面是我的 web 项目的架构图。

Internet --> F5 Load balancer --> Apache web server --> web application

我正在尝试让 Apache Web 服务器从负载均衡器接收来自 Internet 的用户 ip。

但是,我发现是从Apache Web Server接收,而不是来自互联网的用户 ip。F5 ipF5 Load balancer

因此我打开了httpd.conf来自网络服务器并配置了X-Forwarded-For里面的设置,以下是我在里面添加的值httpd.conf

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
# The following line is added by me
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" proxy 

# I commented this following line
#CustomLog logs/access_log combined
# The following 3 lines is added by me
SetEnvIf X-Forwarded-For "^.*\..*\..*\..*" forwarded
CustomLog "logs/access_log" combined env=!forwarded
CustomLog "logs/access_log" proxy env=forwarded

我重新启动apache服务器,但结果仍然相同。我可以知道我为配置设置的错误吗?

4

1 回答 1

3

您需要Insert X-Forwarded-For在 F5 负载均衡器的 HTTP 配置文件中启用该选项:

Local Traffic > Profiles > HTTP 

在此处输入图像描述

于 2019-07-22T14:52:26.863 回答