To log the real IP address of clients behind a reverse proxy or load balancer in Lighttpd, you can use the mod_extforward
module. The mod_extforward
module allows you to extract the client's real IP address from the X-Forwarded-For
HTTP header, which is typically added by a reverse proxy or load balancer.
To enable the mod_extforward
module in Lighttpd, you will need to install the mod_extforward
package and add the following directive to the server.modules
section in your Lighttpd configuration file:
server.modules += ( "mod_extforward" )
Next, you will need to add the following directives to the server.extforward
section in your Lighttpd configuration file to configure the mod_extforward
module:
server.extforward.headers = ( "X-Forwarded-For" ) server.extforward.extractor = ( "lighttpd.extforward.ip" )
These directives tell the mod_extforward
module to extract the client's real IP address from the X-Forwarded-For
HTTP header, and to use the lighttpd.extforward.ip
extractor to parse the header value.
Finally, you will need to update the accesslog.filename
directive to use the %{X-Forwarded-For}
variable to log the client's real IP address. For example:
accesslog.filename = "/var/log/lighttpd/access.log"
After making these changes to your Lighttpd configuration file, you will need to reload the configuration for the changes to take effect. You can use the lighttpd -t
command to test the configuration, and the lighttpd -f /path/to/config.conf
command to reload the configuration.
By enabling the mod_extforward
module and configuring it to extract the client's real IP address from the X-Forwarded-For
HTTP header, you should be able to log the real IP address of clients behind a reverse proxy or load balancer in Lighttpd. You can refer to the Lighttpd documentation and the mod_extforward
documentation for more information on configuring and using the mod_extforward
module.