ted serbinski – entrepreneur & web architect
  • thoughts
  • about
  • contact



Popular content

  • I have left Lullabot...
  • BMW E39 minivan taker
  • DC Drupal Meetup #4
  • myLifetime Community Launches
  • Gorgeous wallpapers
  • How to Keep a Macbook Cool
  • Menu bar 2.0, released from Belgium!
  • SimpleFeed 1.0 ships!
  • Call Me "Driver S"
  • My latest patch: fixing links and breaking modules
more

Recent comments

  • thanks very much
    1 week 4 days ago
  • it is really nice written
    2 weeks 3 days ago
  • Hi, I have used the
    4 weeks 1 day ago
  • thankyou so much and for
    8 weeks 5 days ago
  • It’s typical for the
    10 weeks 2 days ago
more

RightScale & Drupal - How to Get Internal IP Address

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():

  1.   'reverse_proxy' => true,
  2.   'reverse_proxy_addresses' => array(
  3.     // load balancer IPs
  4.     '1.2.3.4', // elastic ip address from AWS
  5.   ),

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:

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

What this basically does is opens up our db.inc 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!

posted 1 Aug 2009
  • drupal
  • rightscale

2 comments

#1
jcmarco wrote 31 weeks 3 days ago

Hi Ted, If you just want to have the remote user ip address and you are using the HA-Proxy configuration from Rightscale then you can just put this on your settings.php, from my point of view is safe enough.

  1. /*
  2. * Support for haproxy, remote ip addres is in the x_forwarded_for
  3. */
  4. $_SERVER['REMOTE_ADDR'] = array_shift(explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']));

If you need the whitelist configuration for anything else, then your option is the best one, but you need to execute a ssh script towards any already existing Drupal server and you need to have that server list in some place.

I look forward to know about your new projects that are probably so exciting as your last ones.

#2
ted wrote 31 weeks 3 days ago

Yes that would work, however, we don’t need the user’s IP address in particular, we need the IP address of the actually machine in our cluster. During boot time we can use the above script to write the IP address to a file so we have it handy at the PHP level with no other trickier :)

Add your comment

The content of this field is kept private and will not be shown publicly.
  • You can use Textile markup to format text.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <p> <img> <pre>
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]". PHP source code can also be enclosed in <?php ... ?> or <% ... %>.

More information about formatting options


Code examples and downloadable zip files of code are licensed under a Creative Commons License.
All other content, unless where noted, ©2010 Theodore Serbinski. All Rights Reserved.