Tag Archives: apache

Get the right IP

Get the right IP

Was currently taking part in moving a WordPress site with a single webserver into a AWS Virtual Private cloud using an ELB to loadbalance multiple webservers.  Ran into an issue where IPs were not being grabbed properly and provided to the WordPress control panel for comment moderation.  I have already enabled the X-FORWARDED-FOR header in apache and wanted WordPress to capture this rather than the VPC IPs.



Placing the following in my wp-config.php made it possible to get the real IP via this header so we can better moderate without requiring registration.  It’s a hack, but it’s a useful one.

// ** bw 2012-08-12 wordpress reverse proxy x-forwarded-for ip fix ** //
  $xffaddrs = explode(',',$_SERVER['HTTP_X_FORWARDED_FOR']);
  $_SERVER['REMOTE_ADDR'] = $xffaddrs[0];
Tagged , ,

don’t do the damn symlink yourself

setting up a vhost in apache on an ubuntu machine?  need to symlink it to sites-enabled?  don’t do it manually you big dummy.

following commands let you create/destroy symlinks for vhosts and apache modules:

a2dismod  a2dissite  a2enmod    a2ensite

so blahblah blah i add a new site for supercoolblog.net

create my vhost in /etc/apache2/sites-available/supercoolblog.net

a2ensite supercoolblog.net

Symlink is added, restart apache and you got your cool site.

Tagged ,