本文共 928 字,大约阅读时间需要 3 分钟。
在本次实验中,我们使用以下三台主机进行配置测试:
10.43.2.21310.43.2.1110.43.2.54访问流程为:A → B → C
在配置文件中进行了如下修改:
server { listen 80; server_name localhost; charset koi8-r; access_log /var/log/nginx/log.host.access.log main; location / { root /usr/share/nginx/html; index index.html index.htm; set_real_ip_from 10.43.2.11; real_ip_header X-Real-IP; }} set_real_ip_from 10.43.2.11;
real_ip_header X-Real-IP;
X-Real-IP 中。log_format
$http_x_forwarded_for_$remote_addr-$remote_user[$time_local],用于记录客户端地址、远程用户信息等。通过实际访问测试,可以看到以下效果:
未修改前:访问日志仅记录代理服务器的 IP 地址,无法获取客户端真实 IP 地址。
修改后:访问日志中成功记录客户端真实 IP 地址,表明 Nginx Web 服务器已正确获取客户端 IP 地址。
通过上述配置方法,我们成功实现了 Nginx Web 服务器获取客户端真实 IP 地址的功能。这种方法在代理服务器和 Web 服务器之间尤其适用,能够确保日志记录的准确性和完整性。
转载地址:http://nhcfk.baihongyu.com/