Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Glad to hear that someone has taken this up. It would be great if nginx support was included.
To purge page http://mysite.com/node/1 from the nginx cache you just need to visit http://mysite.com/purge/node/1. The "/purge/" part is configurable, but that seems to be the convention. http://labs.frickle.com/nginx_ngx_cache_purge/
There are already two Wordpress modules that support nginx cache purging so a Drupal one would be great. (http://wordpress.org/extend/plugins/nginx-manager/ and http://wordpress.org/extend/plugins/nginx-proxy-cache-purge/)
Thanks.
Comments
Comment #1
brianmercer CreditAttribution: brianmercer commentedMight be able to do this with a rewrite. I'll look into that as well.
Comment #2
SqyD CreditAttribution: SqyD commentedSounds like a good feature to have indeed.
I'll look into it. Not too familiar with nginx yet but you just gave me the best excuse ;-)
Would be more nice if you can get nginx to accept the PURGE request... maybe something like (pseudo code)
Comment #3
brianmercer CreditAttribution: brianmercer commentedThanks for looking. That does look promising.
Maybe something like this by defining a separate local port to clear the cache for all your domains, and put the domain in the key:
Let me know when the code is ready for testing. :)
Comment #4
SqyD CreditAttribution: SqyD commentedThat config was just a blind guess from some googling, I'll setup an instance with nginx later this week to actualy play with it a bit. It should be doable...
And yes, thanks. That curl example has an error and should read:
curl -X PURGE -H "Host:example.com" http://192.168.1.23/node/2
When you just use one server you don't need to set the header explicitly but just use:
curl -X PURGE http://example.com/node/2
I'll fix it in the Readme.
Thanks!
Comment #5
brianmercer CreditAttribution: brianmercer commentedOK, I found a config that works.
In response to something like:
it will properly purge the cache and return a 200 if the page exists in the cache and a 404 if the page doesn't exist in the cache.
I installed the 6.x-1.x-dev but it didn't send anything to the web server. I assume the module is not yet ready for community testing.
Thanks again for taking this up.
Comment #6
SqyD CreditAttribution: SqyD commentedIt is ready for testing I believe but it could be this new use case prompts new issues to solve.
- Did the purge module and the expire module put entries in the watchdog log? Please provide both.
- Please provide the url you used to configure the purge module.
Some test ideas:
- Maybe just put "http://test.brianmercer.com" as a proxy url and see if you can find something in the logs.
- Your current setup doesn't check for the PURGE request type and should work with a normal GET request as well. You could test this by commenting out the line in purge.inc that sets this and try if that fixes it.
- My nginx experiment will probably have to wait till Sunday. (drupaldevdays brussels on saturday :-) I still hope there is a clean way to implement the PURGE request just like the others. Your approach may work and if it doesn't require changes in the code I am all for it. The idea of the url prefix /purge/* I will take that into account for future refactoring.
Comment #7
brianmercer CreditAttribution: brianmercer commentedTrying the web address as the proxy url showed me what was happening. Even though I have "http://127.0.0.1:8888" set at admin/settings/purge the request is still going to the actual web site and the purge requests show up in the log for test.brianmercer.com. However, test.brianmercer.com is listening on its public IP: 69.164.210.108:80.
I can't see what curl command the php5-curl module is generating. The odd thing is that in the test.brianmercer.com logs, it looks like the requests are coming from the public IP and not from the localhost. i.e.:
The expire module is adding two watchdog entries that look ok. The purge module is logging an error message for those urls that result in a 301 because of aliases and the Global Redirect module. On my site /node will always result in a 301 to /, and node/3089 will result in a 301 to /title-of-node. The redirect behavior is by design. You'll have to decide how to handle non-200, but correct responses in watchdog if someone is using Global Redirect.
On a different, simpler test site (c.brianmercer.com) I am getting one of these errors for each url:
That might be a PHP 5.3 issue. I run into those occasionally. Oddly I don't get that error on the test.brianmercer.com site.
admin/settings/performance/expire results in a white page. Dunno if that's an expire module issue.
nginx doesn't recognize the PURGE request method. If you send it a PURGE request it returns 405 Method Not Allowed. That is why I need the "error_page 405" directive in there, so that it redirects as a GET.
Comment #8
SqyD CreditAttribution: SqyD commentedOk, thanks for the update. It's more clear to me what is going on.
The more I think about it, the more I tend to go for the nginx "native" approach by adding the /purge/ prefix to the path. They must have done this for a reason... The native method seems a good way to avoid all the redirect problems we run into now. I can't turn up anything usefull on google about this.
I have an idea for a relative simple way to add this native purge feature without having to rewrite half of the module. It's high on my todo list, after drush and rules integration. With that I drop the hard dependency on expire so we can rule out causes of problems there. Shouldn't take that long, the basics of those two features are there, just needs some polishing. (or should I have used "varnishing" in this context ;-)
Comment #9
brianmercer CreditAttribution: brianmercer commentedThis fixed it:
The nginx config still isn't working, so I'll post back when I figure out that part.
Comment #10
brianmercer CreditAttribution: brianmercer commentedOK, found the other one:
Comment #11
brianmercer CreditAttribution: brianmercer commentedSeems to be working wonderfully now.
Thanks again for this project. This is something I've wanted for nginx since the expire module appeared but didn't have the skill to create.
Comment #12
SqyD CreditAttribution: SqyD commentedGreat skills as far as I can see :-) Thank you for finding these embarrassing bugs... I should have tested this piece of code better after my last refactoring. I'll commit your changes plus a first try at drush and rules integration tonight...
Comment #13
SqyD CreditAttribution: SqyD commentedHi,
The .dev release now should have basic "native" nginx support. I need to update the Docs and Gui help messages still. Here's how it works:
<scheme>://<host>[:port][/path]<?purge_method=[purge|get]>
whereExample for nginx:
http://localhost:8080/purge?purge_method=get
In other news: Also the error logging code has been improved and I've also added drush integration to the expire module so all should be good for a test drive. I'll commit after I've updated the docs etc and done a bit more testing myself.
Cheers!
Comment #14
SqyD CreditAttribution: SqyD commentedIt's now in the 1.1 release and mentioned in the Readme and project page. I would still appreciate on independent confirmation this works before I close this one.
Comment #15
crea CreditAttribution: crea commentedSubscribing
Comment #16
omega8cc CreditAttribution: omega8cc commentedNginx 1.0.5
ngx_cache_purge-1.3
PHP-FPM 5.2.17
MariaDB 5.2.7
Debian Squeeze
Nginx and Purge configured per readme etc.
Any attempt to add node or comment results with WSOD because of Nginx crash, however the node or comment is added, only the "purge" request results with:
Not sure if that is ngx_cache_purge broken with Nginx 1.0.5 (will test again with 1.0.1) or it is a problem with purge module.
Comment #17
omega8cc CreditAttribution: omega8cc commentedJust tested it with Nginx 1.0.1 and it results with exactly the same segfault.
What can be wrong here?
BTW: Nginx config used: http://drupalcode.org/project/barracuda.git/blob/HEAD:/aegir/conf/nginx_...
Comment #18
omega8cc CreditAttribution: omega8cc commentedAh, we need to put this in a separate server { } on different port so it doesn't call itself in the same server { } probably.
Comment #19
omega8cc CreditAttribution: omega8cc commentedThis still fails for me.
We use Proxy Url: http://127.0.0.1:8888/purge?purge_method=get with separate vhost: http://drupalcode.org/project/barracuda.git/blob/HEAD:/aegir/conf/nginx_...
Still the same:
Ideas?
Comment #20
Fidelix CreditAttribution: Fidelix commentedomega8cc, I tested with the same config (except PHP version, which is 5.3 here) as your first attempt.
It's not segfaulting here, but I get some random "Not Found" errors, which I'm trying to fix.
Comment #21
SqyD CreditAttribution: SqyD commentedThanks for debugging this. No time this week to help out myself but here are a few ideas to isolate the problem:
- Try to hit the purge url outside of drupal by (for instance) curl or wget and compare results on the nginx side. You bypass PHP with this.
- You can try to use the drush expire commands.
drush xp node/1
Comment #22
omega8cc CreditAttribution: omega8cc commentedNow that is really weird. We changed in Nginx *only* error logging level from crit to debug and it no longer segfaults (why?), but also doesn't purge anything:
Comment #23
omega8cc CreditAttribution: omega8cc commentedUsing curl/wget will not bypass php-fpm here, because it is not a proxy in front of backend Nginx, it is fastcgi_cache_purge method, so in the same Nginx server.
For drush it shows only:
Comment #24
omega8cc CreditAttribution: omega8cc commentedHmm.. it seems a bit random, as now it segfaults again, also with
drush xp node/1
.Comment #25
SqyD CreditAttribution: SqyD commentedThe error log indicates an "error 0" which is weird. It should be 200, 403 etc What would be the result of a manul command like:
curl -v http://d6.o3.linode.us.host8.biz/purge/node/1
At least the ACL works since I get an 403 here. Do you get a 403 in the drupal log when you exclude the localhost in the acl?
Comment #26
Fidelix CreditAttribution: Fidelix commentedThis is the Purge Proxy Url I'm using:
Comment #27
omega8cc CreditAttribution: omega8cc commentedYou will get 404 now, because I reimaged that server and the exact config I'm testing now is:
And when I'm trying locally:
curl -vv -H "Host:d6.o2.linode.us.host8.biz" "http://127.0.0.1:8888/purge/node/2"
It gives:
And of course in the
/var/log/syslog
it results with:Jul 24 15:45:31 localhost kernel: nginx[15035]: segfault at 3 ip 000000000043ef7e sp 00007fff1d1934b8 error 4 in nginx[400000+84000]
And because of this there is nothing logged in
/var/log/nginx/speed_purge.log
Normally, when Nginx segfaults it means we are doing something really bad in its config. But what can be wrong here?
Comment #28
omega8cc CreditAttribution: omega8cc commentedAnd here is a full debug output:
Comment #29
SqyD CreditAttribution: SqyD commentedFrom the error message "Empty reply from server" in the curl command output I think it's safe to conclude the purging module in nginx is the problem, not php, drupal etc. It should return a 200.
Comment #30
omega8cc CreditAttribution: omega8cc commentedBut then why it segfaults also with Nginx 1.0.1 which is known as working for others (WordPress etc) ?
Of course, since it fails purely on the Nginx level, it has nothing to do with PHP, Drupal or your module.
So I guess that possible problems are caused by one of:
1. Some specific settings in my global Nginx config: http://drupalcode.org/project/provision.git/blob/HEAD:/http/nginx/server...
2. Conflict with upload progress module in Nginx (however no idea how it could be connected).
I guess that my next steps should be to remove (one by one) my global settings in Nginx and see where (if) it stops crashing...
Comment #31
omega8cc CreditAttribution: omega8cc commentedRemoved *all* my settings so it is basically vanilla Nginx 1.0.5, with upload progress only, still segfaults. Now to rebuild Nginx w/o upload progress :/
Comment #32
omega8cc CreditAttribution: omega8cc commentedNo difference, so either
fastcgi_cache_purge
is buggy or I'm doing something wrong I have no idea about. I would appreciate any confirmation about working config for Nginx 1.0.5 as I tested already all possible combinations, and none worked for me.Comment #33
Fidelix CreditAttribution: Fidelix commentedomega8cc, what about this?
Host:
http://pastebin.com/vtpfp3Rg
Nginx.conf (where your problem most likely lies in)
http://pastebin.com/4Xp8CHHB
Comment #34
omega8cc CreditAttribution: omega8cc commented@Fidelix
What difference do you mean?
Comment #35
SqyD CreditAttribution: SqyD commented@Fidelix Just reread the thread and noted in #20 your "Not Found" errors. These are probably just normal behaviour of nginx when the object was not in cache. I would not worry about it.
Comment #36
Fidelix CreditAttribution: Fidelix commentedSqyD, but I'm almost sure something about the cache was going wrong:
Editors posted something to homepage, and the homepage was not being updated.
Editors edited some post on the homepage, and the homepage was not being updated.
Users logged in, browsed 1 or 2 pages, and the login block returned.
And this kind of stuff. What could be the problem?
PS: I'm running boost too.
Comment #37
omega8cc CreditAttribution: omega8cc commented@Fidelix
So this config from #33 works for you w/o issues? I see this is mostly copied from my standard config and can't find anything making difference there?
I think I will try this on another VM maybe, as this already drives me crazy ;)
Comment #38
omega8cc CreditAttribution: omega8cc commented@Fidelix
Ah, so disable Boost completely to avoid confusion and then let us know if the Nginx cache/purge works there.
Comment #39
omega8cc CreditAttribution: omega8cc commented@Fidelix
Also, do you include my global.inc in the site's settings.php? It is required or the "speed booster" will never work correctly.
Comment #40
Fidelix CreditAttribution: Fidelix commentedomega, I did not include global.inc, I never realized it was actually needed.
I only did this:
The global.inc you are referring to is this one?
http://gitorious.org/aegir/barracuda-octopus/blobs/master/aegir/conf/ove...
Comment #41
Fidelix CreditAttribution: Fidelix commentedOr is it this one?
http://drupalcode.org/project/barracuda.git/blob/HEAD:/aegir/conf/global...
Comment #42
omega8cc CreditAttribution: omega8cc commented@Fidelix
I mean http://drupalcode.org/project/barracuda.git/blob/HEAD:/aegir/conf/global...
Without Speed Booster related cookies/logic there you will end up with cached pages for logged in users, but "shared" between them, since there will be no
$cookie_OctopusCacheID
in thefastcgi_cache_key
- see http://drupalcode.org/project/barracuda.git/blob/HEAD:/aegir/conf/nginx_...What is even worse, any logged in user will create cached pages, and their (logged in) cached pages will be available for all not logged in visitors for the next hour, while normally those caches are separate and for anonymous visitors valid for one hour, while for logged in users for five minutes only, and created per user, thanks to unique
$cookie_OctopusCacheID
in thefastcgi_cache_key
.Plus, any cached pages created by anonymous visitors will be served also for logged in users, causing "logged out" syndrome.
You should use Barracuda and Octopus or at least derive required bits from my global.inc to make it working properly.
Comment #43
SqyD CreditAttribution: SqyD commentedAny progress on this?
From the thread above I conclude so far no problem has been found in this projects code and possible causes could be related to
- the 3rd party module being not compatible with current nginx releases
- conflicts with complex configurations like Barracuda.
Since I personally still don't use nginx I don't can't spare the time to start testing this myself but would like to know:
- Does it work on plain vanilla nginx and what versions are recommended?
- If not or barely so, should we at least label this experimental for now?
Thanks all for contributing!
Comment #44
attiks CreditAttribution: attiks commentedI tried it as well and it seems to work, here's what I did
1/ nginx.conf, same code as #1048000-27: nginx support
2/ downloaded purge into sites/all/modules/o_contrib
3/ added the following to local.settings.php
4/ did the following as root
Comment #45
SqyD CreditAttribution: SqyD commentedThanks for your helpfull post Attiks. I'll link to it from a few places so other nginx users can find it too.
Comment #46
attiks CreditAttribution: attiks commented@Sqyd: this is done a a development server, and isn't really stress tested, so don't know how it will handle real life situations.
Comment #47
SqyD CreditAttribution: SqyD commentedOk. Good to know. I'll keep revert it to "needs review" untill I hear about a successful production rollout.
Comment #48
attiks CreditAttribution: attiks commentedI tried latest barracuda Barracuda version BOA-1.4S (nginx 1.0.8) with ngx_cache_purge 1.3, 1.4 and HEAD version but all result in segfault at 3 ip 000000000043e119 sp 00007fff92ddf808 error 4 in nginx[400000+80000]
Comment #49
attiks CreditAttribution: attiks commentedtried with nginx 1.0.9 as well but same problem
Comment #50
SqyD CreditAttribution: SqyD commentedI would recommend sending bug reports upstream to the frickle.com people that provided the ngx_cache_purge module for nginx. I don't think there's anything I can do about these issues here.
Comment #51
attiks CreditAttribution: attiks commented@SqyD it was FYI, I'm debugging right now and have it working again doing it manually, for reference:
Comment #52
attiks CreditAttribution: attiks commentedGot it all working again, by commenting out one line inside BARRACUDA
for reference:
Comment #53
omega8cc CreditAttribution: omega8cc commentedIt works great, thanks!
See also: http://drupal.org/node/1329770#comment-5378232
Comment #54
SqyD CreditAttribution: SqyD commentedAwesome. I'll close this feature request. From now on please create separate support requests for upstream problems and bug reports when there are strong indications the underlying problem lies within this projects code.
Thanks to all contributing!