Skip to content

Commit 54fca67

Browse files
authored
Merge pull request #295 from annkots/master
TCR-823: MAx Cache for Nginx public documentation
2 parents b77d4ae + 3c71f81 commit 54fca67

File tree

1 file changed

+261
-1
lines changed

1 file changed

+261
-1
lines changed

docs/cloudlinuxos/shared-pro/README.md

Lines changed: 261 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1886,7 +1886,267 @@ MAx Cache will not work in AccelerateWP when:
18861886
* The site is a WordPress Multisite (the MAx Cache .htaccess block is skipped).
18871887
* The site language is Korean (ko_KR) (the MAx Cache .htaccess block is skipped).
18881888
* Using the AccelerateWP PHP filter to replace dots with underscores.
1889-
* Using the AccelerateWP PHP filter forces the full path to cache files instead of using DOCUMENT_ROOT.
1889+
* Using the AccelerateWP PHP filter forces the full path to cache files instead of using DOCUMENT_ROOT.
1890+
1891+
## MAx Cache for NGINX
1892+
1893+
### Overview
1894+
1895+
MAx Cache for NGINX (`ea-nginx-maxcache`) is the NGINX counterpart of the [Apache MAx Cache module](/cloudlinuxos/shared-pro/#max-cache-documentation) . It serves pre-generated static HTML cache files produced by AccelerateWP directly from disk, bypassing PHP on cache hits. The module shares the same `libmaxcache` core library as the Apache module for device detection, WebP support, cookie handling, and query-string normalization.
1896+
1897+
:::note MAx Cache for NGINX is currently supported on cPanel control panels only. :::
1898+
1899+
### Installation
1900+
1901+
```
1902+
yum install accelerate-wp cloudlinux-site-optimization-module libmaxcache libmaxcache-configd --enablerepo=cloudlinux-updates-testing
1903+
yum install ea-nginx-maxcache --enablerepo=cl-ea4-testing
1904+
```
1905+
1906+
This pulls in all required dependencies:
1907+
1908+
| Package | Description |
1909+
| --------------------- | --------------------------------------------------------------- |
1910+
| `ea-nginx-maxcache` | NGINX dynamic module (`.so` file) and module loader config |
1911+
| `libmaxcache` | Shared C library for device detection, WebP, cookie/QS handling |
1912+
| `libmaxcache-configd` | Configuration daemon: parses `.htaccess`, writes shared memory |
1913+
1914+
Verify the module is loaded:
1915+
1916+
```
1917+
nginx -T 2>&1 | grep maxcache
1918+
# Expected: load_module "/usr/lib64/nginx/modules/ngx_http_maxcache_module.so";
1919+
```
1920+
1921+
The `maxcache-configd` daemon is enabled automatically on package install:
1922+
1923+
```
1924+
systemctl status maxcache-configd
1925+
journalctl -u maxcache-configd -f
1926+
```
1927+
1928+
### Supported modes
1929+
1930+
#### Default: automatic via maxcache-configd daemon
1931+
1932+
In the default mode, the `maxcache-configd` daemon reads AccelerateWP `.htaccess` directives and writes parsed per-domain configuration to shared memory (`/dev/shm/maxcache_config`). The NGINX module reads this shared memory on each request. No manual NGINX configuration is needed per domain.
1933+
1934+
The `maxcache_dynamic` directive (enabled by default) and `maxcache_shm_path` are the only `http`-level directives required. The `ea-nginx-maxcache` package configures them automatically.
1935+
1936+
#### ea-nginx reverse proxy (proxy\_pass)
1937+
1938+
NGINX sits in front of Apache. On a cache hit, the module serves the file directly and Apache is never contacted. On a miss, the request is proxied to Apache as usual.
1939+
1940+
#### ea-nginx standalone (fastcgi\_pass)
1941+
1942+
NGINX handles all traffic without Apache. PHP requests go to PHP-FPM via `fastcgi_pass`. On a cache hit, the module serves the file directly and PHP-FPM is never contacted.
1943+
1944+
#### Manual NGINX configuration
1945+
1946+
For domains not managed by AccelerateWP, static directives (`maxcache on`, `maxcache_path`, exclusions, etc.) can be set directly in `nginx.conf` or included config files. These also serve as fallbacks when the daemon does not have configuration for a domain.
1947+
1948+
### Activation
1949+
1950+
Use the `cloudlinux-awp-admin` tool to enable MAx Cache:
1951+
1952+
```
1953+
# Enable for all compatible sites on the server
1954+
cloudlinux-awp-admin maxcache enable --all
1955+
1956+
# Enable for a specific site
1957+
cloudlinux-awp-admin maxcache --enable --user {USERNAME} --domain {USERDOMAIN}
1958+
```
1959+
1960+
:::tip
1961+
The AccelerateWP plugin must be installed and up-to-date on the target WordPress sites.
1962+
:::
1963+
1964+
### Known issues
1965+
1966+
#### mod\_ruid2 and NGINX standalone mode
1967+
1968+
:::warning
1969+
When using NGINX in **standalone mode** (without Apache), `mod_ruid2` can cause permission issues.
1970+
:::
1971+
1972+
`mod_ruid2` changes file ownership to match the site owner's UID/GID. Cache files may end up with restrictive permissions (e.g., `0700`) that the NGINX `nobody` user cannot read, resulting in cache misses.
1973+
1974+
**Symptoms:**
1975+
1976+
* NGINX always passes requests to the backend despite MaxCache being enabled.
1977+
* NGINX error log shows `permission denied` when opening cache files.
1978+
1979+
**Resolution:**
1980+
1981+
1. Grant group read access to cache directories:
1982+
1983+
```
1984+
chmod -R g+rX /home/username/public_html/wp-content/cache/
1985+
```
1986+
1987+
2. Or use ACLs:
1988+
1989+
```
1990+
setfacl -R -m u:nobody:rX /home/username/public_html/wp-content/cache/
1991+
setfacl -R -d -m u:nobody:rX /home/username/public_html/wp-content/cache/
1992+
```
1993+
1994+
3. Or switch to **ea-nginx reverse proxy (proxy\_pass) mode** (recommended when `mod_ruid2` is active).
1995+
1996+
### Configuration directives
1997+
1998+
All directives below map directly to their [Apache MAx Cache counterparts](https://docs.cloudlinux.com/cloudlinuxos/shared-pro/#max-cache-documentation) . In most deployments with `maxcache_dynamic on` (the default), these are managed automatically by the daemon.
1999+
2000+
#### maxcache
2001+
2002+
Enables or disables the module.
2003+
2004+
**Syntax:** `maxcache on | off;` **Default:** `off` **Context:** `http`, `server`, `location`
2005+
2006+
#### maxcache\_path
2007+
2008+
Cache file path template with variable substitution.
2009+
2010+
**Syntax:** `maxcache_path "<template>";` **Default:** none (required when `maxcache on`) **Context:** `http`, `server`, `location`
2011+
2012+
Supported template variables:
2013+
2014+
| Variable | Description | Example value |
2015+
| ------------------------- | ----------------------------------------- | ------------------- |
2016+
| `{HTTP_HOST}` | Request hostname | `example.com` |
2017+
| `{REQUEST_URI}` | Request URI path | `/blog/hello-world` |
2018+
| `{SSL_SUFFIX}` | `-https` if HTTPS, empty otherwise | `-https` |
2019+
| `{MOBILE_SUFFIX}` | `-mobile` for mobile/tablet devices | `-mobile` |
2020+
| `{WEBP_SUFFIX}` | `-webp` if browser supports WebP | `-webp` |
2021+
| `{GZIP_SUFFIX}` | `_gzip` if client accepts gzip | `_gzip` |
2022+
| `{QS_SUFFIX}` | Normalized query string suffix | `#lang=en` |
2023+
| `{USER_SUFFIX}` | Per-user cache suffix for logged-in users | `-admin-a1b2c3` |
2024+
| `{USER_SHARED_SUFFIX}` | Shared logged-in cache suffix | `-loggedin-a1b2c3` |
2025+
| `{DYNAMIC_COOKIE_SUFFIX}` | Dynamic cookie variant suffix | `-fr-eur` |
2026+
2027+
#### maxcache\_options
2028+
2029+
Behavior options for mobile handling.
2030+
2031+
**Syntax:** `maxcache_options [+|-]skip_mobile [+|-]tablet_as_mobile [+|-]export_vars;` **Default:** all disabled **Context:** `http`, `server`, `location`
2032+
2033+
| Option | Description |
2034+
| ------------------ | ------------------------------------------------------------------ |
2035+
| `skip_mobile` | Mobile devices bypass cache and receive dynamic content. |
2036+
| `tablet_as_mobile` | Tablets are treated as mobile devices. |
2037+
| `export_vars` | Exports `$cl_device_type` and `$cl_supports_webp` NGINX variables. |
2038+
2039+
#### maxcache\_exclude\_uri
2040+
2041+
Regex (case-insensitive) to exclude matching URIs from caching.
2042+
2043+
**Syntax:** `maxcache_exclude_uri "<regex>";` **Default:** none **Context:** `http`, `server`, `location`
2044+
2045+
#### maxcache\_exclude\_ua
2046+
2047+
Regex (case-insensitive) to exclude matching User-Agents from caching.
2048+
2049+
**Syntax:** `maxcache_exclude_ua "<regex>";` **Default:** none **Context:** `http`, `server`, `location`
2050+
2051+
#### maxcache\_exclude\_cookie
2052+
2053+
Regex (case-insensitive) to exclude requests with matching cookies from caching.
2054+
2055+
**Syntax:** `maxcache_exclude_cookie "<regex>";` **Default:** none **Context:** `http`, `server`, `location`
2056+
2057+
#### maxcache\_mandatory\_cookies
2058+
2059+
Cookies that must be present for the module to serve cached content.
2060+
2061+
**Syntax:** `maxcache_mandatory_cookies <cookie1> [cookie2] ...;` **Default:** none **Context:** `http`, `server`, `location`
2062+
2063+
##### maxcache\_dynamic\_cookies
2064+
2065+
Cookies that create dynamic cache variants (e.g., for multi-currency or multi-language).
2066+
2067+
**Syntax:** `maxcache_dynamic_cookies <cookie1> [cookie2] ...;` **Default:** none **Context:** `http`, `server`, `location`
2068+
2069+
#### maxcache\_qs\_allowed\_params
2070+
2071+
Query string parameters allowed in the cache key. Without this, any query string bypasses the cache.
2072+
2073+
**Syntax:** `maxcache_qs_allowed_params <param1> [param2] ...;` **Default:** none **Context:** `http`, `server`, `location`
2074+
2075+
#### maxcache\_qs\_ignored\_params
2076+
2077+
Query string parameters to strip from the cache key (typically tracking params).
2078+
2079+
**Syntax:** `maxcache_qs_ignored_params <param1> [param2] ...;` **Default:** none **Context:** `http`, `server`, `location`
2080+
2081+
#### maxcache\_ignore\_headers
2082+
2083+
Request header/value pairs that bypass the cache. Format: `"Header-Name: value"`.
2084+
2085+
**Syntax:** `maxcache_ignore_headers "<Header>: <value>";` **Default:** none **Context:** `http`, `server`, `location`
2086+
2087+
#### maxcache\_logged\_hash
2088+
2089+
Secret hash for logged-in user cache keys. Must match AccelerateWP's `secret_cache_key` setting.
2090+
2091+
**Syntax:** `maxcache_logged_hash "<secret_key>";` **Default:** none **Context:** `http`, `server`, `location`
2092+
2093+
#### maxcache\_dynamic
2094+
2095+
Enables dynamic per-domain configuration from the `maxcache-configd` daemon via shared memory.
2096+
2097+
**Syntax:** `maxcache_dynamic on | off;` **Default:** `on` **Context:** `http`
2098+
2099+
#### maxcache\_shm\_path
2100+
2101+
Path to the shared memory file for daemon-to-module configuration exchange.
2102+
2103+
**Syntax:** `maxcache_shm_path <path>;` **Default:** `/dev/shm/maxcache_config` **Context:** `http`
2104+
2105+
Must match the `shm_path` setting in `/etc/maxcache/configd.conf`.
2106+
2107+
### Troubleshooting
2108+
2109+
**Module not loaded:**
2110+
2111+
```
2112+
nginx -T 2>&1 | grep maxcache
2113+
```
2114+
2115+
**Cache files missing or wrong permissions:**
2116+
2117+
```
2118+
ls -la /home/user/public_html/wp-content/cache/example.com/
2119+
sudo -u nobody test -r /home/user/public_html/wp-content/cache/example.com/index-https.html && echo "OK" || echo "Permission denied"
2120+
```
2121+
2122+
**Daemon not running:**
2123+
2124+
```
2125+
systemctl status maxcache-configd
2126+
journalctl -u maxcache-configd --since "1 hour ago"
2127+
ls -la /dev/shm/maxcache_config
2128+
```
2129+
2130+
**Force rescan after migrations:**
2131+
2132+
```
2133+
systemctl reload maxcache-configd
2134+
```
2135+
2136+
**Check domain is registered in daemon:**
2137+
2138+
```
2139+
echo '{"action":"status"}' | socat - UNIX-CONNECT:/opt/cloudlinux/maxcache/notify.sock
2140+
```
2141+
2142+
**Debug logging:**
2143+
2144+
```
2145+
error_log /var/log/nginx/error.log debug;
2146+
```
2147+
2148+
Look for entries prefixed with `maxcache:`.
2149+
18902150
18912151
## Centralized Monitoring
18922152

0 commit comments

Comments
 (0)