---
title: "lighttpd获取nginx代理客户端真实IP"
author: "calmness"
date: "2009-05-11T11:45:51Z"
tags: []
categories: ["编程语言"]
slug: "lighttpd-nginx-ip"
draft: false
lastmod: "2009-05-11T11:45:51Z"
id: 383511
url: "https://calmness.iteye.com/blog/383511"
---

在使用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获取真实客户端地址。