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.
6 thoughts on “Running Drupal behind a reverse proxy”
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!
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.
cool. thanks for your help! i’ll try and retro-fit it for Drupal 5 and see how it goes.
When I moved our drupal server behind a reverse proxy I lost all styles and functionality. Did you have to do anything special?
Is it still possible to convert the Drupal 6 patch for Drupal 5?
There is no automatic method. You will have to do it your self.