Feb
10
2008

Running Drupal behind a reverse proxy

I was supposed to move one of the Drupal sites I’m maintaining behind a Reverse Proxy. The migration was smooth as it could get, but soon throttiling was an issue. All requests were coming from the Proxy server, and Drupal didn’t seem to automagically detect the client IP based on the X-Forwarded-For header.

So I set about investigating what can be done. As I discovered, automagic client IP detection is only available in Drupal 6 (At the time of writing, under development). I went about porting the changes to Drupal 5.x. Porting was as easy as it can be, but it was not working.

Further investigation lead to one of the site configurations; I had enabled Normal Caching in the Drupal site. It was not acceptable to switch off caching, so I went about debugging this code to make it work with caching enabled. Finally I was able to fix the issue, it was trivial but it was not easy to debug. The fix involved removing cached IP address for every request such that the correct IP will be detected. See my patch in drupal.org at http://drupal.org/node/219825.

Hope this helps someone.

Bookmark and Share

If you enjoyed this post, make sure you subscribe to my RSS feed!

Related posts

Written by S H Mohanjith in: Apache HTTP Server, Drupal, proxy | Tags: , ,

6 Comments »

  • stephen

    I have a question about this. You say this patch is for Drupal 5, but it looks like it’s for Drupal 6. Do you have code or instructions for running Drupal 5 behind a reverse proxy? Thanks!

    Comment | February 12, 2008
  • mohanjith

    The patch was submitted for Drupal 6, but you could do something similar for Drupal 5.

    You can use the ip_address function as it is, then replace all occurences of $_SERVER['REMOTE_ADDR'] with ip_address(). Also do not forget to include ip_address(true); in index.php

    Hope this helps, if not let me know, I’ll create a patch for Drupal 5.

    Comment | February 12, 2008
  • stephen

    cool. thanks for your help! i’ll try and retro-fit it for Drupal 5 and see how it goes.

    Comment | February 12, 2008
  • Brandon Dixon

    When I moved our drupal server behind a reverse proxy I lost all styles and functionality. Did you have to do anything special?

    Comment | October 6, 2008
  • Is it still possible to convert the Drupal 6 patch for Drupal 5?

    Comment | April 17, 2009
  • There is no automatic method. You will have to do it your self.

    Comment | April 17, 2009

RSS feed for comments on this post. TrackBack URL

Leave a comment

S H Mohanjith © 2009 | Powered by WordPress | Aeros Theme