Rocket-Nginx Documentation
repository·master·Indexed 20 days ago
https://github.com/satellitewp/rocket-nginxAn Nginx configuration layer for the WP Rocket WordPress plugin that enables high-performance static file serving by bypassing PHP for cached content. It includes a configuration parser for .ini files, support for custom configuration includes (v3.0+), debug headers for cache hit/miss analysis, and guidelines for managing system-level cron jobs and SSL/HTTPS support.
What's inside Rocket-Nginx
- Rocket-Nginx is an Nginx configuration designed for the WP Rocket WordPress cache plugin. It optimizes performance by allowing Nginx to serve previously cached files directly, bypassing WordPress and PHP execution. It also implements headers to leverage browser caching for CSS, JS, and media files.
New features in Rocket-Nginx v3.x
masterVersion 3.x introduced several significant changes and features:
- Query String Support: You can now specify query strings to cache via the
.inifile. Refer to WP Rocket's Cache query strings documentation for configuration details. - Query String Ignoring: You can specify query strings to ignore via the
.inifile. Refer to WP Rocket's Cache query strings to ignore documentation. - Custom Expirations: Support for custom expiration settings for CSS, JS, and media files.
- Section Includes: Custom configurations can now be included in every section.
- Removed Features:
- The default HSTS value has been removed.
- Adding headers directly from the config file has been removed (use the hook principle instead).
- Query String Support: You can now specify query strings to cache via the
SSL/HTTPS Support in Rocket-Nginx
masterRocket-Nginx supports HTTPS. It automatically detects whether a request is made via HTTP or HTTPS and serves the appropriate file based on the protocol.Use custom configuration includes in Rocket-Nginx
masterStarting with version 3.0, you can inject custom Nginx configuration snippets into specific stages of the request lifecycle by placing files in the
rocket-nginx/conf.d/default/directory using specific filename patterns:Filename Pattern Injection Point start.*.confBefore Rocket-Nginx starts global.*.confGlobally in every section http.*.confIn the HTTP section preprocess.*.confPreprocess (after all variables are set) css.*.confIn the CSS section js.*.confIn the JS section media.*.confIn the Media section Upgrade from Rocket-Nginx v1 or v2 to v3
masterVersion 3.x is not backward-compatible with versions 1 or 2. To upgrade:
- Save your existing configuration as a backup.
- Start with a fresh configuration to ensure all new features and structural changes are correctly implemented.
- Review the new configuration options, as many behaviors have changed.
Debug Rocket-Nginx cache hits and misses
masterTo inspect how Nginx is serving files, enable debug mode in
rocket-nginx.ini:debug = trueResponse Headers
All requests include the following header:
X-Rocket-Nginx-Serving-Static: Indicates if the file was served directly (HIT,MISS, orBYPASS).
When
debug = true, the following additional headers are added:X-Rocket-Nginx-Reason: If the status is notHIT, explains why WordPress was called (e.g.,Post request,Arguments found,Maintenance mode,Cookie,Specific mobile cache activated, orFile not cached). IfHIT, shows the URL used.X-Rocket-Nginx-File: IfHIT, shows the absolute path to the file on disk.X-Rocket-Nginx-Device: Indicates the detected device (desktopormobile).
debug = trueInstall Rocket-Nginx
masterTo install Rocket-Nginx, clone the repository into your Nginx configuration directory (typically
/etc/nginx/).cd /etc/nginx git clone https://github.com/satellitewp/rocket-nginx.gitSince version 2.0, the configuration must be generated using the included parser:
cd rocket-nginx cp rocket-nginx.ini.disabled rocket-nginx.ini php rocket-parser.phpThis generates a
default.conffile. You must then include this file in your Nginx server block:server { ... # Rocket-Nginx configuration include rocket-nginx/conf.d/default.conf; ... }Finally, test and reload Nginx:
nginx -t service nginx reloadcd /etc/nginx git clone https://github.com/satellitewp/rocket-nginx.gitEnable BF Cache (Back/forward cache) compatibility
masterRocket-Nginx is compatible with BF Cache. If your website is suitable for back/forward caching (i.e., it does not display sensitive user data), you must manually edit your Rocket-Nginx configuration to enable it. Detailed implementation guidance can be found in the official GitHub issue discussion.Disable WordPress Cron and set up a real Cron job
masterBecause Rocket-Nginx serves cached files without executing PHP, standard WP-Cron jobs (which rely on site visits) may not trigger. It is strongly recommended to disable WordPress's internal cron and use a system-level cron job instead.
- Add this to your
wp-config.php:
define( 'DISABLE_WP_CRON', true );- Set up a manual cron job (e.g., every 15 minutes) using one of these methods:
Using wget:
*/15 * * * * wget -q -O - http://www.website.com/wp-cron.php?doing_wp_cron &>/dev/nullUsing curl:
*/15 * * * * curl http://www.website.com/wp-cron.php?doing_wp_cron &>/dev/nullUsing PHP CLI:
*/15 * * * * cd /home/user/public_html; php wp-cron.php &>/dev/nulldefine( 'DISABLE_WP_CRON', true );- Add this to your
Configure Rocket-Nginx via .ini file
masterRocket-Nginx is configured using a
rocket-nginx.inifile. You can add site-specific configurations by creating a new section. For example, to add a custom cookie that invalidates the cache:[example.com : default] cookie_invalidate[] = "my_custom_cookie"Important: Every time you modify the
.inifile, you must regenerate the Nginx configuration and reload the service:- Regenerate:
php rocket-parser.php - Test Nginx config:
nginx -t - Reload Nginx:
service nginx reload
[example.com : default] cookie_invalidate[] = "my_custom_cookie"- Regenerate:
Resolve lost Nginx headers using the hook principle
masterIf you find that
add_headerdirectives are missing after enabling Rocket-Nginx, this is due to how Nginx manages headers. To fix this, use the 'hook' principle:- Define your custom headers in a separate configuration file.
- Include that file within your Rocket-Nginx configuration.
- If the header file is located outside the expected directory, you can use a symbolic link to ensure it is accessible.
Refer to the Configuration section of the documentation to identify the correct placement for these headers.
Known limitations of Rocket-Nginx
masterEncoded Slugs
Encoded slugs (e.g., non-Latin characters) may not be served correctly due to case-sensitivity differences between browsers and Nginx. Note: Version 3.1.0+ provides a
preprocess.*.confinclude to help mitigate this by forcing$rocket_uri_pathto lowercase.WebP Compatibility
Rocket-Nginx cannot serve WebP files generated by the WP Rocket WebP Compatibility feature. If this feature is enabled, Rocket-Nginx will bypass the cache and let WordPress/WP Rocket handle the request to ensure the correct image format is served.