|
1 | 1 | Rocket-Nginx
|
2 | 2 | ============
|
3 | 3 |
|
4 |
| -Nginx configuration for WP-Rocket |
| 4 | +Rocket-Nginx is a [Nginx](http://nginx.org) configuration for the [WordPress](http://wordpress.org) cache plugin [WP-Rocket](http://wp-rocket.me). |
| 5 | + |
| 6 | +## <a name='toc'>Table of Contents</a> |
| 7 | + |
| 8 | + 1. [Contributors](#contributors) |
| 9 | + 1. [Before You Start](#before) |
| 10 | + 1. [Installation](#installation) |
| 11 | + 1. [Configuration](#configuration) |
| 12 | + 1. [Debug](#debug) |
| 13 | + 1. [FAQ](#css) |
| 14 | + 1. [License](#license) |
| 15 | + |
| 16 | +## <a name='contributors'>Contributors</a> |
| 17 | + |
| 18 | +The configuration was created and is maintained by [Maxime Jobin](http://www.maximejobin.com) ([@maximejobin](http://twitter.com/maximejobin)). |
| 19 | + |
| 20 | +## <a name='before'>Before You Start</a> |
| 21 | +As the configuration's goal is to serve cached files directly without having to execute any PHP from WordPress, this may cause your scheduled jobs to not be called. As you may already know, WP-Cron jobs are not real cron jobs and are executed only when you have visits on your site. |
| 22 | + |
| 23 | +In order to make sure your scheduled tasks are run when they should, it is strongly suggested to disable WordPress cron jobs and create a real cron job. |
| 24 | + |
| 25 | +To disable WordPress cron job, add the following line to your `wp-config.php`: |
| 26 | +`define('DISABLE_WP_CRON', true);` |
| 27 | + |
| 28 | +Then, manually a cron job every 15 minutes (it should be enough for most websites): |
| 29 | +`*/15 * * * * wget -q -O - http://www.website.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1` |
| 30 | +or |
| 31 | +`*/15 * * * * curl http://www.website.com/wp-cron.php?doing_wp_cron > /dev/null 2>&1` |
| 32 | +or |
| 33 | +`*/15 * * * * cd /home/user/public_html; php wp-cron.php > /dev/null 2>&1` |
| 34 | + |
| 35 | +Make sure you test that your tasks still run after this change! |
| 36 | + |
| 37 | +## <a name='installation'>Installation</a> |
| 38 | + |
| 39 | +In order to use the script, you must include it in your actual configuration. Only one instance of Rocket-Nginx is needed for all your WordPress websites using WP-Rocket. |
| 40 | + |
| 41 | +You can create a folder `rocket-nginx` directory in your Nginx configuration directory. If you are using Ubuntu, your Nginx configuration (nginx.conf) should be found in: `/etc/nginx/`. |
| 42 | + |
| 43 | +To install, you can: |
| 44 | + ``` |
| 45 | + cd /etc/nginx |
| 46 | + git clone https://github.com/maximejobin/rocket-nginx.git |
| 47 | + ``` |
| 48 | + |
| 49 | +Then, in your configuration file, you must [include](http://nginx.org/en/docs/ngx_core_module.html#include) the configuration. If your websites configurations are in `/etc/nginx/sites-available`, you need to alter your configuration: |
| 50 | + |
| 51 | +``` |
| 52 | +server { |
| 53 | + include rocket-nginx/rocket-nginx.conf |
| 54 | +} |
| 55 | +``` |
| 56 | + |
| 57 | +Before you reload your configuration, make sure you test it: |
| 58 | +`nginx -t` |
| 59 | + |
| 60 | +Once your test is done, you must reload your configuration. |
| 61 | +`service nginx reload` |
| 62 | + |
| 63 | +That's it. |
| 64 | + |
| 65 | +## <a name='configuration'>Configuration</a> |
| 66 | +There is no configuration to do. |
| 67 | + |
| 68 | +By default, files such as CSS, JS and images are cached for 30 days (`expires 30d;`). As of the latest Nginx stable version, it is not possible to set these values into variables. You can manually change the values if needed. |
| 69 | + |
| 70 | +## <a name='debug'>Debug</a> |
| 71 | +You may want to check if your files are served directly by Nginx and not calling any PHP. To do that, open the `rocket-nginx.conf` file and change the debug value from: |
| 72 | + |
| 73 | +`set $rocket_debug 0;` |
| 74 | + |
| 75 | +To: |
| 76 | + |
| 77 | +`set $rocket_debug 1;` |
| 78 | + |
| 79 | +This will add the following headers to your response request: |
| 80 | + * **X-Rocket-Nginx-Bypass**: Did the configuration served the cached file directly (did it bypass WordPress): Yes or No. |
| 81 | + * **X-Rocket-Nginx-Reason**: If "No", what is the reason for calling WordPress. If "Yes", what is the file used. |
| 82 | + |
| 83 | + |
| 84 | +Reasons for not serving a cached file: |
| 85 | + * **Post request**: The request to the web server was a POST. That means data was sent and the answer may need to be different from the cached file (e.g. when a comment is sent). |
| 86 | + * **Arguments found**: One or more argument was found in the request (e.g. ?page=2). |
| 87 | + * **Maintenance mode**: The .maintenance file was found. Therefore, let's WordPress handle what should be displayed. |
| 88 | + * **Cookie**: A specific cookie was found and tells to not serve the cached page (e.g. user is logged in, post with password). |
| 89 | + * **File** not cached: No cached file was found for that request. |
| 90 | + |
| 91 | +## <a name='faq'>FAQ</a> |
| 92 | +No frequently asked questions... so far. |
| 93 | + |
| 94 | +## <a name='license'>License</a> |
| 95 | +Released under the [GPL](http://www.gnu.org/licenses/gpl.html). See the link for details. |
0 commit comments