WordPress Comments and Varnish

After along time searching for the answer to fix my issue of where users post a comment and the IP address in the comment is of my Varnish server not the clients IP address who made the comment. Well this issue is now resolved after finding this post! http://theterminaladmin.com/wordpress-comments-and-varnish/

Ironically I couldn’t post a comment of gratitude onto his word-press site as I got a submitting error.

Just in-case is website disipears his post was the following:

While setting up this site I ran into an issue where comments posted were reporting the IP address as 127.0.0.1. This looked to be coming from Varnish and luckily, is fixable by editing two WordPress files.

The first is $document_root/wp-includes/pluggable.php. Add the following lines anywhere in the file:

if ( !function_exists('get_user_real_ip') ) { function get_user_real_ip() { $userip = ( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR']; return $userip; } }

The second is $document_root/wp-includes.comment.php:

Replace the following line:

 $commentdata['comment_author_IP'] = preg_replace( '/[^0-9a-fA-F:., ]/', '',$_SERVER['REMOTE_ADDR'] );

With:

 $commentdata['comment_author_IP'] = preg_replace( '/[^0-9a-fA-F:., ]/', '',get_user_real_ip() );

A simple fix but it works. You may need to re-apply this if you update/re-install WordPress but that is trivial at this point considering how easy it is :)

Web Server Upgrade Time Baby!

After many years of having my website hosted on a generic home-made server I have  upgraded to a newer server.

The new server is a HP ProLiant DL360 G3 with the specs-
CPU x2: Intel Xeon 3.06GHz
RAM: 2.5Gb ECC
HDD: x2 146.6GB SCSI 10,000RPM in a RAID1

The old server was a Intel D845EWD entry-level server motherboard with the specs-
CPU: Intel Pentium 4 3.0GHz
RAM: 2Gb non ECC
HDD x2 80 IDE in a RAID 1, 3x 300Gb SATA1 in a RAID5 on a Adaptec PCI Hardware RAID controller
Case: Antec beige tower

The choice of which Linux distribution to use was a not a decision I look lightly. In the end Ubuntu 12.04 LTS won over Centos 6.2. Both operating systems offered an awesome Enterprise OS but I am familiar with Ubuntu and already use it on my desktop and other servers.

I upgraded my firewall server a few weeks ago and since then have performed some tweaks to varnish the reverse web proxy service and now my website should load quicker and almost be slashdot proof. I think only only issue now is my lack of upload bandwidth and my ADSL router is crappy.