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.

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

6 thoughts on “Running Drupal behind a reverse proxy”

  1. 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!

  2. 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.

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

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.