mirror, mirror on the wall

mirror, mirror on the wall

thttpd patch for logging proxy.

Posted on .

I am using relayd to relay incomming connections to thttpd server. Every http request is logged with IP address of the relayd server not with the real client IP address. Part of relayd.conf file:

...
http protocol httpssl {
        header append "$REMOTE_ADDR" to "X-Forwarded-For"
        header append "$SERVER_ADDR:$SERVER_PORT" to "X-Forwarded-By"
...

Relayd adds X-Forwarded-For and X-Forwarded-By fields into HTTP header. With the following patch thttpd will read them and real client IP will appear in log file.

...
[123.123.123.123] by [127.0.0.1:8443] - - [03/Dec/2013:15:50:48 +0200] "GET / HTTP/1.1" 200 857 "" \
"Mozilla/5.0 (X11; FreeBSD amd64; rv:17.0) Gecko/17.0 Firefox/17.0"
...
# tar zxvf thttpd-2.25b.tar.bz
# cp thttpd-log-proxy.patch thttpd-2.25b/
# cd thttpd-2.25b/
# patch < thttpd-log-proxy.patch
# ./configure
# make
# make install

I am using relayd for proxy but if you prefer you can use another software. Just make sure X-Forwarded-For and X-Forwarded-By will appear in the HTTP header.

About

github

Creative Commons

RSS