Nginx map issue?

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

Hi all,

I'm trying out an nginx + boost + pressflow 6 setup using perusio's config. So far it's working well (thanks for all the great work!), but I'm having a couple issues:

1) The home page appears to be always cached by boost, even for logged in users.

2) Submitting a form is causing nginx to return a 405 error. Googling around, I learned that nginx won't post to a static file, so it appears that somehow my configuration is letting POST's go to the boost cached files, rather than to index.php.

If I add the following to the location @cache then it fixes the second problem:

if ($request_method = POST) {
        return 418;
}

This seems to indicate that something is going wrong with the map directives in the map_cache.conf file. However, the map $http_cookie $no_cache directive seems to be working (at least for most pages... perhaps just not the home page).

I'd appreciate any tips for solving these issue.

Thanks,
Chad

Comments

Hmm. Can you please try

perusio's picture

the following hypothetical fix.

Thanks.

Thanks for your quick reply.

chadcrew's picture

Thanks for your quick reply. I already have that fix in my config. I think perhaps the problem was mapping the $no_cache variable twice in the map_cache.conf file. It was defined to check for POST's and SESS cookies:

## Testing the request method. Only GET and HEAD are caching
## safe. This is only needed for Boost. If using microcaching you
## comment out the map directive below.
map $request_method $no_cache {
    default 0;
    POST 1; # POST requests aren't cached usually
}

## Testing for the session cookie being present. If there is then no
## caching is to be done. Note that this is for someone using either
## Drupal 7 pressflow or stock Drupal 6 core with no_anon
## (http://drupal.org/project/no_anon).
map $http_cookie $no_cache {
    default 0;
    ~SESS 1; # PHP session cookie
}

Only the SESS check was working for me. If I comment the SESS check block out, then the POST check works.

I'm still not sure why the home page is always cached.

Best,
Chad

Yep

perusio's picture

it was too complicated and wrong. To be correct using the map directive requires 4 variables. It can be done with Lua (http level):

set $no_cache 0;
set_by_lua $no_cache 'if (ngx.var.request_method == "POST") or ngx.re.match(ngx.var.http_cookie, "SESS") return 1 end';

In the meantime I've posted a "fix" (I hope) on github. Try it out.

Thanks,

EDIT: I haven't tested it the first time and in fact it's required to use an if and return explicitly to make it work. Lua is sort of functional, but there are some oddities. Now this works.

Front page

chadcrew's picture

For the issue of the front page always being cached, can you explain the purpose of this block at the top of drupal_boost6.conf:

    location = / {
        try_files /cache/normal/$host/${args}.html /cache/perm/$host/.css /cache/perm/$host/_.js /cache/$host/0/.html /cache/$host/0/index.html /index.php;
    }

I thought that the boost cache was being handled with the try_files in the @cache section.

If I comment out that location = / block at the top of drupal_boost6.conf, then the home page is no longer cached for logged in users, but is still cached for anon users. I think everything is working right now, but I'm not sure if removing that block could cause any problems.

Thanks,
Chad

Well

perusio's picture

Boost is really a pack of wild cats. I added that location because someone complained about the front page not being cached. If it works for you you may comment it out/remove it. AFAICT it has no additional consequences.

Hah, okay sounds good.

chadcrew's picture

Hah, okay sounds good.

Nginx

Group organizers

Group notifications

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

Hot content this week