Dec 15

How to: Purge Http and Https caches in NginX with NginX Helper

How to: Purge Http and Https caches in NginX with NginX Helper

If I had a wish list, it would be remote purge and supporting custom purging expressions/keys. Regardless, If you edit the file nginx-helper/purger.php and modify some lines you can send your purge request to both your http and https server. In my case my caching key uses the scheme as the referenced elements might be using https if you visit the site using https. Here is the function that send the purge request that you can modify as I have highlighted:

 

function purgeUrl( $url, $feed = true ) {

$this->log( “- Purging URL | ” . $url );

$parse = parse_url( $url );

$_url_purge_base = ‘http://’ . $parse[ ‘host’ ] . ‘/purge’ . $parse[ ‘path’ ];

$_url_purge = $_url_purge_base;

if ( isset( $parse[ ‘query’ ] ) && $parse[ ‘query’ ] != ” ) {

$_url_purge .= ‘?’ . $parse[ ‘query’ ];

}

$this->_do_remote_get( $_url_purge );

$_url_purges_base = ‘https://’ . $parse[ ‘host’ ] . ‘/purge’ . $parse[ ‘path’ ];

$_url_purges = $_url_purges_base;

 

if ( isset( $parse[ ‘query’ ] ) && $parse[ ‘query’ ] != ” ) {

$_url_purges .= ‘?’ . $parse[ ‘query’ ];

}

 

$this->_do_remote_get( $_url_purges );

if ( $feed ) {

$feed_url = rtrim( $_url_purge_base, ‘/’ ) . ‘/feed/’;

$this->_do_remote_get( $feed_url );

$this->_do_remote_get( $feed_url . ‘atom/’ );

$this->_do_remote_get( $feed_url . ‘rdf/’ );

$feed_urls = rtrim( $_url_purges_base, ‘/’ ) . ‘/feed/’;

$this->_do_remote_get( $feed_urls );

$this->_do_remote_get( $feed_urls . ‘atom/’ );

$this->_do_remote_get( $feed_urls . ‘rdf/’ );

}

}

The result as expected is that both http and https caches now are purged:

2013-12-16 04:33:32 | INFO | * * * * *

2013-12-16 04:33:32 | INFO | * Blog :: Knowledge eXchange (#).

2013-12-16 04:33:32 | INFO | * Post :: How to: Purge Http and Https caches in NginX with NginX Helper (1234).

2013-12-16 04:33:32 | INFO | * Post (1234) published or edited and its status is published

2013-12-16 04:33:32 | INFO | * * * * *

2013-12-16 04:33:32 | INFO | Function purgePost BEGIN ===

2013-12-16 04:33:32 | INFO | Purging homepage ‘http://kx.cloudingenium.com/’

2013-12-16 04:33:32 | INFO | – Purging URL | http://kx.cloudingenium.com/

2013-12-16 04:33:32 | INFO | – – http://kx.cloudingenium.com/purge/ *** PURGED ***

2013-12-16 04:33:32 | INFO | – – http://kx.cloudingenium.com/purge/ is currently not cached

2013-12-16 04:33:32 | INFO | – – http://kx.cloudingenium.com/purge/feed/ *** PURGED ***

2013-12-16 04:33:32 | INFO | – – http://kx.cloudingenium.com/purge/feed/atom/ is currently not cached

2013-12-16 04:33:32 | INFO | – – http://kx.cloudingenium.com/purge/feed/rdf/ is currently not cached

2013-12-16 04:33:33 | INFO | – – https://kx.cloudingenium.com/purge/feed/ is currently not cached

2013-12-16 04:33:34 | INFO | – – https://kx.cloudingenium.com/purge/feed/atom/ is currently not cached

2013-12-16 04:33:35 | INFO | – – https://kx.cloudingenium.com/purge/feed/rdf/ is currently not cached

[…]

 

Enhanced by Zemanta

Leave a Reply

%d bloggers like this: