Hinweis: Dieser Artikel wurde ursprünglich veröffentlicht in 2013. Einige Schritte, Befehle oder Softwareversionen haben sich möglicherweise geändert. Überprüfen Sie die aktuelle Dokumentation von NginX für die neuesten Informationen.

Voraussetzungen

Bevor Sie beginnen, stellen Sie sicher, dass Sie Folgendes haben:

  • A Linux server with Nginx installed
  • Root or sudo access to the server
  • Basic understanding of web server configuration

How to: Purge Http and Https caches in (http://nginx.org/ “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 . ‘/purge’ . $parse; $_url_purge = $_url_purge_base; if ( isset( $parse ) && $parse != ” ) { $_url_purge .= ’?’ . $parse; } $this->_do_remote_get( $_url_purge ); $_url_purges_base = ‘https://’ . $parse . ‘/purge’ . $parse; $_url_purges = $_url_purges_base; if ( isset( $parse ) && $parse != ” ) { $_url_purges .= ’?’ . $parse; } $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 ’/’ 2013-12-16 04:33:32 | INFO | - Purging URL | / 2013-12-16 04:33:32 | INFO | - - / *** PURGED *** 2013-12-16 04:33:32 | INFO | - - / is currently not cached 2013-12-16 04:33:32 | INFO | - - / *** PURGED *** 2013-12-16 04:33:32 | INFO | - - / is currently not cached 2013-12-16 04:33:32 | INFO | - - / is currently not cached 2013-12-16 04:33:33 | INFO | - - / is currently not cached 2013-12-16 04:33:34 | INFO | - - / is currently not cached 2013-12-16 04:33:35 | INFO | - - / is currently not cached

 

(http://img.zemanta.com/zemified_h.png?x-id=2a62a4c3-770e-4225-bb6f-fbf4bde83f62)](http://www.zemanta.com/?px “Enhanced by Zemanta”)

Zusammenfassung

Verwandte Artikel