Welcome

Registration encouraged by invitation. Write to invitations at this website name.
RoadSkater.Net skating & cycling photos!

Donate to keep RoadSkater.Net free!

Search & shop eBay to support RoadSkater.Net...
Search RoadSkater.Net via Google...
Search the web...

Help How To Apache2 Server Access Log Lists Only IP Address 127.0.0.1 (Every Line): Squid, Varnish or Other Reverse Proxy

roadskater's picture

Pulling through the trees of Ubuntu Server 8.10 (aka Intrepid Ibex), Memcache, Squid, Varnish, APC, PHP, Apache, MySQL and other LAMPmines, it's easy enough to miss a note here and there. One of those sour notes I hit continued unnoticed until I checked the server logs and every line began with 127.0.0.1, the local loopback address.

127.0.0.1 - - [25/Jan/2009...
127.0.0.1 - - [25/Jan/2009...

I'd like to say I instantly got it, but no. It took awhile. I initially thought this had been the case since the initial installation, but after looking back far enough, I found this not to be the case. At that point it was easier to find the problem as I knew I had experimented with using Nginx server, Varnish and Squid as reverse proxies (to stuff some pages in memory instead of on disk for brief periods to speed up access, particularly for anonymous users (where there's less dynamic content generated).

I hear distant bells and did some searches (which were difficult because 127.0.0.1 is included in a lot of questions and answers. The joke being on me, I found the answer in the log file itself! Doh!

# If you are behind a reverse proxy, you might want to change %h into %{X-Forwarded-For}i
In the config line for the log file format, %h is the IP address of the client (usually a remote host) that made the request to the server. In this case, however, Apache is getting the request from Varnish (or Squid) reverse proxy.

The i percent-directive, %{header}i, is to display the value of a specific HTTP request header. In this case Varnish passes along the original requestor in an HTTP request header parameter called X-Forwarded-For. Once I edited the config file (I use nano but vi and others work)...
nano /etc/apache2/apache2.conf
...commenting the first line here and adding the second one...
#LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined

...and saved the file, then restarted Apache2...

/etc/init.d apache2 restart

...my access log file will began to give some useful information again. Good old Google, Yahoo, MSN, somebody with Fedora 1.4, all the data you need to stare at into the dawn.

No this is not about skating, but I hope it helps somebody out there!

Syndicate content Syndicate content