perusio / drupal-with-nginx

Running Drupal using nginx: an idiosyncratically crafted bleeding edge configuration.
854 stars 246 forks source link

Nginx cache with purge capability #285

Closed cptX closed 6 years ago

cptX commented 6 years ago

Today I discovered the nginx cache capability and I realized that is actually equally powerful to Varnish. The only problem is that I couldn't make automatic selective purges of the updated nodes (in Drupal 6). So I spent the whole day trying to implement a purging capability but I really didn't succeed at all!

I'm using the code from this project (perusio/drupal-with-nginx) and I tried to use these tutorials https://docs.nginx.com/nginx/admin-guide/content-cache/content-caching/#purge https://github.com/FRiCKLE/ngx_cache_purge/ replacing every proxy* with fastcgi*

nginx reloads without errors so all the caching and purging functionality exists in the corresponding module of nginx (module http-cache-purge found through nginx -V)

The problem is that I cannot purge any page. If I do curl -X PURGE -D – "http://site/page/to/purge" I always receive 405 Not Allowed from the server. I also tried to allow 127.0.0.1 with the geo command, but nothing...

Of course tried to enable modules Cache Expiration and Purge in Drupal again without success. So, how can I enable purge functionality in nginx for Drupal 6?

It would be a miracle if we could achieve a Varnish functionality without using Varnish at all, and we are already so close as the cache works. If we achive the selective purge functionality it will make our setup optimal!


In order to be more specific I'll explain here what I did:

geo $purge_allowed {
   default         1;  # deny from other
   127.0.0.1        1;  # allow from localhost
}

map $request_method $purge_method {
   PURGE   $purge_allowed;
   default 0;
}

Then reloaded nginx without errors and tried curl -X PURGE -D – "http://site/page/to/purge" which gave me 405 Not Allowed

cptX commented 6 years ago

So after a hard day of reading and experimenting, I was successful. I now have a system that uses nginx and works as if there was varnish on top of it.

I was based on this article with a lot of modifications and of course adjusting it for Drupal 6 (with php7.2 support): https://easyengine.io/wordpress-nginx/tutorials/single-site/fastcgi-cache-with-purging/