Aegir/Nginx : Boost rewrite rules don't work for site root / <front> page

Events happening in the community are now at Drupal community events on www.drupal.org.
smoothify's picture

I'm using Aegir & Nginx combination (through omega8cc's great barracuda install scripts), and everything is fine and dandy.

However, when using Boost, I can get every page to cache correctly except for the homepage or a site.

The Boost rules are set to allow it, and I can see in the cache directory that the file is getting saved as it should (it becomes _.html).

Whenever you try to access the page while logged out, it just doesn't return the cached version. I therefore believe that the problem is in the rewrite rules and since this is nginx specific, i thought here might be a good place to ask.

I've tried with both the simple and advanced configuration files for provision but neither work for this.

The cache rules in the simple conf file are:

    ###
    ### catch all unspecified requests
    ###
    location / {
        #try_files $uri $uri/ @cache;
        if (!-e $request_filename) {
          break;
        }
        error_page 404 = @cache;
    }

    ###
    ### boost compatible cache check
    ###
    location @cache {
        if ( $request_method !~ ^(GET|HEAD)$ ) {
            return 405;
        }
        if ($http_cookie ~ "DRUPAL_UID") {
            return 405;
        }
        error_page 405 = @drupal;
        add_header Expires "Tue, 24 Jan 1984 08:00:00 GMT";       
        add_header Cache-Control "must-revalidate, post-check=0, pre-check=0";
        add_header X-Header "Boost Citrus 1.9";              
        charset utf-8;
        #try_files /cache/normal/$host${uri}$args.html @drupal;
        if (-f $document_root/cache/normal/$host${uri}
$args.html) {
          rewrite ^/(.+)$ /cache/normal/$host${uri}_$args.html last;
          break;
        }
        error_page 404 = @drupal;
    }

    ###
    ### send all not cached requests to drupal with clean URLs support
    ###
    location @drupal {
        if (!-e $request_filename) {
           rewrite ^/\?q=([^.]+)$  /index.php?q=$1 last;
           rewrite ^/(.*)$         /index.php?q=$1 last;
           break;
        }
    }

and in advanced it is:

    ###
    ### catch all unspecified requests
    ###
    location / {
        try_files $uri $uri/ @cache;
    }

    ###
    ### boost compatible cache check - nginx 0.7.27 or newer required with try_files support
    ###
    location @cache {
        if ( $request_method !~ ^(GET|HEAD)$ ) {
            return 405;
        }
        if ($http_cookie ~ "DRUPAL_UID") {
            return 405;
        }
        error_page 405 = @drupal;
        add_header Expires "Tue, 24 Jan 1984 08:00:00 GMT";       
        add_header Cache-Control "must-revalidate, post-check=0, pre-check=0";
        add_header X-Header "Boost Citrus 1.9";              
        charset utf-8;
        try_files /cache/normal/$host${uri}_$args.html @drupal;
    }

    ###
    ### send all not cached requests to drupal with clean URLs support
    ###
    location @drupal {
        rewrite ^/(.*)$  /index.php?q=$1 last;
    }

Can anyone see anything amiss in here that would cause the site root not to work correctly?

Comments

try special location to front page

Xaber's picture

try

location = / {
try_files /?q=$uri @cache;
}

I now have this working, it

smoothify's picture

I now have this working, it required two changes though - one similar to Xaber's suggestion (thanks)

    ###
    ### catch requests for the site root
    ###
    location = / {
        try_files $uri @cache;
    }

Then for the simple.conf file, I also needed to change the regexp pattern in the @cache declaration:

From
rewrite ^/(.+)$ /cache/normal/$host${uri}_$args.html last;

To :
rewrite ^/(.*)$ /cache/normal/$host${uri}_$args.html last;

The problem was that it wouldn't match due to the + requiring at least one character in the string which the root wouldn't have.

Good catch

omega8cc's picture

You are right about wrong rewrite in the simple config. It was probably some copy/paste fail.

However there is no need for separate location in the advanced config. Instead, it should be changed from:

    ###
    ### catch all unspecified requests
    ###
    location / {
        try_files $uri $uri/ @cache;
    }

to:

    ###
    ### catch all unspecified requests
    ###
    location / {
        try_files $uri @cache;
    }

Not sure how/why we introduced that $uri/ but it definitely breaks Boost support for the site homepage. I'm going to fix that in the provision HEAD and in the Barracuda/Octopus.

Thanks!

Nginx drupal

karthick62's picture

Hi,

I need a help

is there any way to access drupal sub directory with out actually creating a symbolic link? If so , how the configuration must be ?

Nginx

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

Hot content this week