mod_extforward: Lighttpd Log Clients Real IP Behind Reverse Proxy / Load Balancer

I‘ve setup 5 lighttpd web servers behind Nginx 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.


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              = (
                    ### add mod_extforward ####

Add Your Proxy Server / Revers Proxy Load Balancer IPs

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

  extforward.forwarder = (
     "" => "trust",
     "" => "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")


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

Restart Lighttpd

Finally, restart the lighttpd web server, enter:
# service lighttpd restart
You can view access log using tail command:
# tail -f /var/log/lighttpd/access.log

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 0 comments... add one

CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
0 comments… add one

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre> for code samples. Problem posting comment? Email me @