在使用nginx做反向代理时,lighttpd在后端默认是无法获得客户端真实IP,如果要做到后端获取真实IP,首先nginx需要重新编译,加入–with-http_realip_module作为参数,大概如下:
./configure –with-http_realip_module
nginx.conf的proxy_pass后加入如下指令:
Location ~ / {
proxy_pass 127.0.0.1:8080;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
注:Lighttpd只能通过X-Forwarded-For头获取realip,设置X-Real-IP是无效的。
Nginx配置好后,lighttpd仍然无法获得真实ip,必须在lighttpd中添加模块mod_extforward,并进行相应配置,步骤如下:
1、在server.modules中增加mod_extforward
2、指定forwarder ip:
extforward.forwarder = (”10.0.0.232″ => ”trust”)
通过以上配置即可实现后端lighttpd获取真实客户端地址。
./configure –with-http_realip_module
nginx.conf的proxy_pass后加入如下指令:
Location ~ / {
proxy_pass 127.0.0.1:8080;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
注:Lighttpd只能通过X-Forwarded-For头获取realip,设置X-Real-IP是无效的。
Nginx配置好后,lighttpd仍然无法获得真实ip,必须在lighttpd中添加模块mod_extforward,并进行相应配置,步骤如下:
1、在server.modules中增加mod_extforward
2、指定forwarder ip:
extforward.forwarder = (”10.0.0.232″ => ”trust”)
通过以上配置即可实现后端lighttpd获取真实客户端地址。
本文介绍如何配置Nginx和Lighttpd以确保后端服务器能够正确获取客户端的真实IP地址。需要对Nginx进行特定模块的编译,并在配置文件中设置proxy_pass指令;同时,Lighttpd需要添加mod_extforward模块并进行相应的配置。

1万+

被折叠的 条评论
为什么被折叠?



