How to make Drupal 5.x work properly on Nearly Free Speech

When it comes to webhosting, you can't beat NearlyFreeSpeech. They're cheap, fast, and reliable. I've been a very happy customer for years, and run a number of Drupal installations under them.

However, NFSN does do things a little differently, and this can cause some interesting interactions with Drupal. The main thing that they do differently is that they use Squid and run reverse proxies at the edge of their network, which cache requests made to member websites. For most sites, this is not a problem. Drupal, however, tries to be "cache friendly" with regards to the headers it emits, and sometimes this doesn't work so well. I've seen the following symptoms happen under a virgin Drupal installation:

  • Going to the site, and instead of getting the page you wanted to see, having the file download dialog come up.
  • Seeing stale copies of pages.
  • Logging out, and seeing pages indicating that you are still "logged in".
  • Logging in, and seeing pages indicating that you are still logged out.

Here's how to fix that:

  • Open the includes/ file, taking care to make a backup copy first.
  • Go to the function drupal_page_header() and replace the calls to header() with the following calls:
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
    header("Cache-Control: no-store, no-cache, must-revalidate, proxy-revalidate");
    header("Cache-Control: post-check=0, pre-check=0", FALSE);
  • Continue down until you get to the drupal_page_cache_header() function. Comment out the header() call that emits a "304 Not Modified" header" and the following exit() call there. The rest of the header() calls in that funciton should be left alone.
  • Finally, to assist with troubleshooting, edit the page.tpl.php file for whatever theme you are using, and add the following line in the footer:
    Page last generated: <?php print date("r"); ?>

    By examining that line, you can tell whether you are retrieving the most recent copy of the page or not, and this can be a valuable tool in troubleshooting cached pages.

Once all of those things are done, any cache issues that your users are experiencing should slowly go away.

Finally, I must admit that I am not any sort of HTTP guru. I merely followed what I read in these specifications:

If you know of a better way to fix this problem, feel free to let me know...

Average: 2.8 (8 votes)
Your rating: None