GIT – Lighttpd Log Clients Real IP Behind Reverse Proxy / Load Balancer 

I’ve setup 5 lighttpd web servers behind based reverse proxy / load balancer to distribute load for busy e-commerce website. However, all web server nodes putting my load balncers two IP address in access log file. How do I force lighttpd to log a real IP (public IP) address of all client computers visiting our website?

You need to use mod_extforward under Lighttpd to extract and log the client’s real IP from “X-Forwarded-For” or “X-Real-IP” header which is added by reverse proxy server such as Nginx or Squid proxy server.

Configuration

Edit lighttpd.conf file, enter:

# vi /etc/lighttpd/lighttpd.conf

WARNING! mod_extforward is included in lighttpd 1.4.14 and later.

Add mod_extforward at the end of server.modules directive (order is important):

server.modules              = (
                               "mod_redirect",
                               "mod_alias",
                               "mod_rewrite",
                               "mod_expire",
                               "mod_access",
                               "mod_auth",
                               "mod_status",
                               "mod_fastcgi",
                               "mod_secdownload",
                               "mod_accesslog",
                               "mod_compress",
                               ### add mod_extforward ####
                               "mod_extforward"
)

Add Your Proxy Server / Revers Proxy Load Balancer IPs

Add your nginx based reverse proxy ips (LB’s IPs) such as 10.10.28.5 and 10.10.28.6:

 extforward.forwarder = (
     "10.10.28.5" => "trust",
     "10.10.28.6" => "trust"
  )

Save and close the file.

How Do I Set Client’s Custom IP Headers?

You can also set headers to search for finding the client’s original IP addresses using the following syntax:

    extforward.headers = ("X-Cluster-Client-Ip")

OR

    extforward.headers = ("X-Real-Ip")

Restart Lighttpd

Finally, restart the lighttpd web server, enter:

# service lighttpd restart

You can view access log using tail :

# tail -f /var/log/lighttpd/access.log

Table of Contents:

  1. CentOS / Redhat Linux: Install Keepalived To Provide IP Failover For Web Cluster
  2. CentOS / Redhat: Install nginx As Reverse Proxy Load Balancer
  3. Handling nginx Failover With KeepAlived
  4. nginx: Setup SSL Reverse Proxy (Load Balanced SSL Proxy)
  5. mod_extforward: Lighttpd Log Clients Real IP Behind Reverse Proxy / Load Balancer
  6. HowTo: Merge Apache / Lighttpd / Nginx Server Log Files
  7. Linux nginx: Chroot (Jail) Setup

Thảo luận bài viết tại forum : http://forum.gocit.vn/threads/mod-extforward.661/

Print Friendly

Comments

comments

Bài viết liên quan