在 Apache 日志中配置显示真实 IP 地址
在使用 Bitrix 7 时,您可能会发现服务器日志中显示的不是用户的真实 IP 地址,而是 Nginx 服务器的 IP 地址 (127.0.0.1)。这是因为 Nginx 作为 Apache 前端的可选反向代理服务器导致的。
要修复此问题,请执行以下步骤:
1. 打开配置文件 /etc/httpd/conf/httpd.conf:
vim /etc/httpd/conf/httpd.conf
2. 找到以下几行代码:
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
3. 将其中的 %h 替换为 %{X-Forwarded-For}i,修改后的代码如下所示:
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b" common
4. 保存更改并退出文件:
:wq
此外,如果您更习惯使用 nano 编辑器而不是 vim,可以通过以下命令安装:
yum install -y nano