Skip to content

RightScale & Drupal - How to Get Internal IP Address

1 min read

I’m working on a new project that has a Drupal site running in the cloud–specifically Amazon AWS with RightScale sitting on top to manage our servers and automated scaling scripts.

The advantage of RightScale is it allows us to manage our servers at a further abstracted layer than AWS itself – through the use of “RightScripts” we can script our way through the managing of low level resources.

Things started to get a bit hairy when our scripts needed to talk to Drupal, in particular, registering each new server as it comes online with our Drupal stack, thereby whitelisting its IP address as trustworthy.

I did some googling and couldn’t find a good, efficient way to automate this, except for a post with a handy command.

With a little bit of tweaking, I arrived at a working solution that was even easier than thought.

First step is to prepare your settings.php or similar configuration file that holds your $conf[] for Drupal. We use IP address for a number of internal variables, but below are two Drupal specific variables used in ip_address():

  'reverse_proxy' => true,
  'reverse_proxy_addresses' => array(
    // load balancer IPs
    '', // elastic ip address from AWS

The above code lives in our custom file that holds our Drupal $conf[] settings. We have a RightScript that copies this files to the proper location and after the file is copied over, I added this command:

sed -i "/load balancer IPs/ a\'$(hostname -i)',"

What this basically does is opens up our file which holds our Drupal $conf[], it searches for that specific “@load balancer IPs@” string (see above code snippet for where it was defined), than it appends a new line, adding in the IP address of that machine. If you have multiple machines registering themselves, this works quite nicely, as they keep growing the list.

Hope this helps someone else from banging their head around for a few hours!


Related Posts

MothersClick Acquired by Lifetime Networks [] and the rest of the ParentsClick Network []have been acquired by Lifetime Entertainment [] . I’ve been working on this site and with Dietrich (CEO & founder) for over 2

news — 5 min read

Leo talks about the new site

At the end of last week’s TWiT episode [], Leo and company talk about the new site []. A clip of that can be listened to below. Also last week on the Lullabot podcast []

code — 1 min read

My first 15 min of fame!

A few weeks back, Leo Laporte [] approached Lullabot [] about developing the new TWiT website []. Well we gladly accepted, I mean, this is Leo! So I was put in charge of developing the new site, and

code — 1 min read