Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#323, #325, #343 #344

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 91 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Nginx Helper #
[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)

**Contributors:** rtcamp, rahul286, saurabhshukla, manishsongirkar36, faishal, desaiuditd, darren-slatten, jk3us, daankortenbach, telofy, pjv, llonchj, jinnko, weskoop, bcole808, gungeekatx, rohanveer, chandrapatel, gagan0123, ravanh, michaelbeil, samedwards, niwreg, entr, nuvoPoint, iam404, rittesh.patel, vishalkakadiya, BhargavBhandari90, vincent-lu, murrayjbrown, bryant1410, 1gor, matt-h, pySilver, johan-chassaing, dotsam, sanketio, petenelson, nathanielks, rigagoogoo, dslatten, jinschoi, kelin1003, vaishuagola27, rahulsprajapati, Joel-James, utkarshpatel, gsayed786, shashwatmittal, sudhiryadav, thrijith, stayallive, jaredwsmith, abhijitrakas, umeshnevase, sid177, souptik, arafatkn, subscriptiongroup, akrocks
**Contributors:** rtcamp, rahul286, saurabhshukla, manishsongirkar36, faishal, desaiuditd, darren-slatten, jk3us, daankortenbach, telofy, pjv, llonchj, jinnko, weskoop, bcole808, gungeekatx, rohanveer, chandrapatel, gagan0123, ravanh, michaelbeil, samedwards, niwreg, entr, nuvoPoint, iam404, rittesh.patel, vishalkakadiya, BhargavBhandari90, vincent-lu, murrayjbrown, bryant1410, 1gor, matt-h, pySilver, johan-chassaing, dotsam, sanketio, petenelson, nathanielks, rigagoogoo, dslatten, jinschoi, kelin1003, vaishuagola27, rahulsprajapati, Joel-James, utkarshpatel, gsayed786, shashwatmittal, sudhiryadav, thrijith, stayallive, jaredwsmith, abhijitrakas, umeshnevase, sid177, souptik, arafatkn, subscriptiongroup, akrocks, gnif, jeffcleverley(GridPane)

**Tags:** nginx, cache, purge, nginx map, nginx cache, maps, fastcgi, proxy, redis, redis-cache, rewrite, permalinks

Expand Down Expand Up @@ -61,17 +61,67 @@ For proper configuration, check out our **tutorial list** in the [Description ta

No. You need to make some changes at the Nginx end. Please check our [tutorial list](https://easyengine.io/wordpress-nginx/tutorials/).

**Q. Can I set the cache type using wp-config.php constants**

Nginx Helper only helps purge the cache, but it needs to know what type of Nginx page caching you are using.

You can set these in the nginx-helper admin settings, or control them using constants defined in the `wp-config.php` file:

```php
# Tell the plugin you are using fastcgi caching

define( ' RT_WP_NGINX_HELPER_CACHE_METHOD', 'enable_fastcgi' );

# Tell the plugin you are using redis caching

define( ' RT_WP_NGINX_HELPER_CACHE_METHOD', 'enable_redis' );
```

### FAQ - Nginx Fastcgi Cache Purge ###

**Q. There's a 'purge all' button? Does it purge the whole site?**

Yes, it does. It physically empties the cache directory. It is set by default to `/var/run/nginx-cache/`.
Well that depends on your server configuration.

There are three options

If your cache directory is different, you can override this in your wp-config.php by adding
`define('RT_WP_NGINX_HELPER_CACHE_PATH','/var/run/nginx-cache/');`
1. Purge by GET request - using the FRiCKLE ngx_cache_purge module
2. Purge by GET request - using the Torden ngx_cache_purge module
3. Delete local server cache files

If your Nginx server has a the same webserver system user (likely www-data) as your sites directory/files owner then option 3 will purge all by physically emptying the cache directory. It is set by default to `/var/run/nginx-cache/`.
If your server has multiple sites, then this would be a security risk however, so it is likely the Nginx User and Site system user will differ... and purge all will not work.

If your cache directory is different, you can override this in your wp-config.php by adding:

```php
define( 'RT_WP_NGINX_HELPER_CACHE_PATH', '/path/to/your/nginx-cache/' );
```

Replace the path with your own.

If your Nginx server is compiled with the FRiCKLE ngx_cache_purge module, then Purge All is not available

If your Nginx server is compiled with the Torden ngx_cache_purge module, then Purge All will work.

**Q. Can I set the fastcgi purge type using constants**

You can set the purge type from the nginx-helper wp-admin settings page, or use a constants defined in the `wp-config.php:

```php
# Delete local server cache files with unlink_files

define( 'RT_WP_NGINX_HELPER_PURGE_METHOD', 'unlink_files' );

# Delete cache using GET requests when Nginx is compiled with FRiCKLE ngx_cache_purge module

define( 'RT_WP_NGINX_HELPER_PURGE_METHOD', 'get_request' );

# Delete cache using GET requests when Nginx is compiled with Tordent ngx_cache_purge module

define( 'RT_WP_NGINX_HELPER_PURGE_METHOD', 'get_request_torden' );
```

**Q. Does it work for custom posts and taxonomies?**

Yes. It handles all post-types the same way.
Expand Down Expand Up @@ -101,16 +151,40 @@ To purge a page immediately, follow these instructions:

### FAQ - Nginx Redis Cache ###

**Q. Can I override the redis hostname, port and prefix?**
**Q. What connection settings does Nginx Helper suppor for purging the cache?**

The plugin supports:
* Hostname + Port (will be ignored if Unix socket is set)
* Unix sockets (will override Hostname + Port)
* Redis Prefix
* Redis Databases
* Redis ACLs (username and password)

Yes, you can force override the redis hostname, port or prefix by defining constant in wp-config.php. For example:
You can set these parameters via the Nginx Helper wp-admin settings

**Q. Can I set the Redis Connection parameters using constants**

Yes you can, setting them via constant will override these settings in the wp-admin

```php
define( 'RT_WP_NGINX_HELPER_REDIS_HOSTNAME', '10.0.0.1' );
# If using hostname and port both must be set - either in config or via wp-admin

define( 'RT_WP_NGINX_HELPER_REDIS_HOSTNAME', '127.0.0.1' );
define( 'RT_WP_NGINX_HELPER_REDIS_PORT', '6379' );

# If Unix Socket is set then hostname and port will be ignored.

define( 'RT_WP_NGINX_HELPER_REDIS_UNIX_SOCKET', '/run/redis/redis.sock' );

define( 'RT_WP_NGINX_HELPER_REDIS_PORT', '6000' );
# Prefix and database allow for some degree of cache isolation for performance

define( 'RT_WP_NGINX_HELPER_REDIS_PREFIX', 'page-cache:' );
define( 'RT_WP_NGINX_HELPER_REDIS_PREFIX', 'nginx-cache:' );
define( 'RT_WP_NGINX_HELPER_REDIS_DATABASE', '0' );

# Username and password require Redis ACLs but allow for secure cache isolation

define( 'RT_WP_NGINX_HELPER_REDIS_USERNAME', 'user' );
define( 'RT_WP_NGINX_HELPER_REDIS_PASSWORD', 'password' );
```

### FAQ - Nginx Map ###
Expand Down Expand Up @@ -139,6 +213,14 @@ Please post your problem in [our free support forum](https://github.com/rtCamp/n

## Changelog ##

### 2.2.6 ###

* Added Fastcgi purge all capability using GET requests IF Torden ngx_cache_purge module is available. [#323](https://github.com/rtCamp/nginx-helper/issues/323) - by [Geoffrey McRae - gnif](https://github.com/gnif) and [GridPane - Jeff Cleverley](https://github.com/gridpane)
* Added Redis Unix Socket connections. [325](https://github.com/rtCamp/nginx-helper/issues/325) - by [GridPane - Jeff Cleverley](https://github.com/gridpane)
* Added Redis DB selection. [343](https://github.com/rtCamp/nginx-helper/issues/343) - by [GridPane - Jeff Cleverley](https://github.com/gridpane)
* Added Redis ACL. [343](https://github.com/rtCamp/nginx-helper/issues/343) - by [GridPane - Jeff Cleverley](https://github.com/gridpane)
* Added Management of all FastCGI and Redis Connection Parameters by wp-config.php constants. [343](https://github.com/rtCamp/nginx-helper/issues/343) - by [GridPane - Jeff Cleverley](https://github.com/gridpane)

### 2.2.5 ###

* Add the capability to enable/disable purging of feeds. [#281](https://github.com/rtCamp/nginx-helper/issues/281) - by [Amaan Khan](https://github.com/pathan-amaankhan)
Expand Down
56 changes: 55 additions & 1 deletion admin/class-fastcgi-purger.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ public function purge_url( $url, $feed = true ) {

case 'get_request':
// Go to default case.

case 'get_request_torden':
// Go to default case.

default:
$_url_purge_base = $this->purge_base_url() . $parse['path'];
$_url_purge = $_url_purge_base;
Expand Down Expand Up @@ -137,6 +141,10 @@ public function custom_purge_urls() {

case 'get_request':
// Go to default case.

case 'get_request_torden':
// Go to default case.

default:
$_url_purge_base = $this->purge_base_url();

Expand Down Expand Up @@ -166,9 +174,55 @@ public function custom_purge_urls() {
*/
public function purge_all() {

$this->unlink_recursive( RT_WP_NGINX_HELPER_CACHE_PATH, false );
global $nginx_helper_admin;

$purge_method = $nginx_helper_admin->options['purge_method'];

switch ( $purge_method ) {

case 'get_request_torden':
$site = get_site_url();
/** @noinspection PhpLanguageLevelInspection */
// Torden GET is guarded to detect 5.5+ in admin page and inform of incompatibility
$find = [ 'http://', 'https://' ];
$replace = '';
$host = str_replace( $find, $replace, $site);

if ( is_ssl() ) {
$purgeurl = $site . '/purgeall' ;
$curl = curl_init( $purgeurl );
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PURGE" );
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
/** @noinspection PhpElementIsNotAvailableInCurrentPhpVersionInspection */
// Torden GET is guarded to detect 5.5+ in admin page and inform of incompatibility
curl_setopt($curl, CURLOPT_RESOLVE, array($host . ":443:127.0.0.1" ));
} else {
$curl = curl_init( "http://127.0.0.1/purgeall" );
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Host:' . $host ));
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PURGE" );
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE);
}

$response = curl_exec($curl);
if ($response === false)
$this->log( curl_errno($curl) .': '. curl_error($curl) );
curl_close($curl);
break;

case 'get_request':
// Go to default case.

default:
$this->unlink_recursive( RT_WP_NGINX_HELPER_CACHE_PATH, false );
break;
}

$log_purge_method = '* Using: ' . $purge_method;

$this->log( '* * * * *' );
$this->log( '* Purged Everything!' );
$this->log( $log_purge_method );
$this->log( '* * * * *' );

/**
Expand Down
Loading