As said initially by authors of this configuration, it enables nginx to serve directly previously cached files without calling WordPress or any PHP. You will go from NGINX → PHP-FPM → PHP → Static file to NGINX → Static file. In other words, you are serving the static file directly from NGINX instead of passing the request to FPM and then to PHP (for WP-Rocket... at least) before serving the static file.
In combination with myVesta CP settings (and nginx), it also adds headers to cache CSS, JS, and medias to leverage the browser's cache by reducing requests to your web server. By using this, you can noticeably speed-up WordPress sites, and in another hand, reduce the load on the server.
Rocket-Nginx was created by SatelliteWP and they deserve credit for all the content related to it.
Table of contents:
- Important notices before installation
- Automatic installation with our script
- Manual installation
- WP-Cron jobs
- Testing if everything is working
Some IMPORTANT notices before we start:
- The following is a full and comprehensive guide available on their GitHub page: https://github.com/SatelliteWP/rocket-nginx
- Please check for updates and adjust the settings below in accordance with any updates after 26th Feb 2022 (when this post is released)
- This is not officially supported or maintained by myVesta CP and you are using this configuration on your responsibility.
- For purpose of this tutorial, we set everything up on a demo server with myVesta CP. It is recommended that you test this before using it on your production server.
In order to follow along with this tutorial, we have already set up myVestaCP using - viewtopic.php?t=81
Steps:
1. Make sure WP Rocket is activated on your WordPress website
2. Then, get the latest build of myVesta.
In your SSH, as root, run:
Code: Select all
v-update-myvesta
Code: Select all
v-activate-rocket-nginx YOURDOMAIN.COM
Here you can see script code: https://github.com/myvesta/vesta/blob/m ... cket-nginx
4. Test if everything is working
(for experienced users)
Let's jump on the installation steps:
Starting with the very beginning, keep in mind that there are 3 parts to the setup:
- First which is done in the terminal
- Second which is done on myVesta CP
- Third which is done on WordPress
1. In order to follow along with this tutorial, we have already set up myVestaCP using - viewtopic.php?t=81
2. Now let's install rocket-nginx
Code: Select all
cd /etc/nginx
git clone https://github.com/satellitewp/rocket-nginx.git
cd rocket-nginx
cp rocket-nginx.ini.disabled rocket-nginx.ini
php rocket-parser.php
Code: Select all
server {
...
# Rocket-Nginx configuration
include rocket-nginx/conf.d/default.conf;
...
}
Code: Select all
cd /usr/local/vesta/data/templates/web/nginx/
cp force-https.tpl force-https-wprocketnginx.tpl
cp force-https.stpl force-https-wprocketnginx.stpl
mcedit force-https-wprocketnginx.tpl #here we will add code from the step 3.
mcedit force-https-wprocketnginx.stpl #here we will add code from the step 3.
It's also important to add %docroot% and %sdocroot% on appropriate place in order for this piece of code to work
Second part - myVesta CP:
5. That's all you need to do in the terminal. Now let's open myVesta CP and go to the desired domain where we installed WordPress and click Edit for that domain:
6. Under Proxy Template we have to chose previously created nginx template with our rocket-nginx configuration:
7. Go to the end of that page and click Save
8. Go back to terminal and reload nginx configuration but before that - make sure everything is fine with this command:
Code: Select all
nginx -t
Code: Select all
service nginx reload
10. Basicaly everything you have to do here is just to have WP Rocket caching plugin installed and activated.
Your scheduled jobs may not be called because the configuration relies on serving cached files directly from WordPress without having to execute any PHP.
Disabling WordPress cron jobs and creating a real cron job will ensure your scheduled tasks will run when they should.
In your WordPress-config.php, add the following line to disable WordPress cron jobs:
Code: Select all
define( 'DISABLE_WP_CRON', true );
Code: Select all
cd /home/user/web/domain.com/public_html; /usr/bin/php7.4 wp-cron.php >/home/user/web/domain.com/cron.log 2>&1
In the case that your website uses a different PHP version from 7.4, insert that version instead of 7.4
At the end, in your SSH, as root, run:
Code: Select all
touch /home/user/web/domain.com/cron.log
chown user:user /home/user/web/domain.com/cron.log
Go to the your website and clear the WP Rocket cache and let it to preload cache again
Now, open your browser in incognito mode (we are using Chrome), open your website and do the following:
- Right click -> Inspect
- Click the network tab and select "All"
- Ctrl+R to reload
- Click your website name in the left hand side at the top
- Under “Headers” scroll down until you see X-Rocket-Nginx-Serving-Static
“X-Rocket-Nginx-Serving-Static: HIT”
Our goal (as shown above) is to get a HIT. In addition, you can try refreshing and checking again if you didn't receive a HIT (and turn on the debug below to find out why).
To turn on debug - run following in the terminal:
Code: Select all
mcedit /etc/nginx/rocket-nginx/rocket-nginx.ini
Code: Select all
debug = false
Code: Select all
debug = true
Code: Select all
php rocket-parser.php
Code: Select all
nginx -t
Code: Select all
service nginx reload
- X-Rocket-Nginx-Serving-Static: Did the configuration served the cached file directly : HIT, MISS, BYPASS. This will add the following headers to your response request:
- X-Rocket-Nginx-Reason: If serving static is not set to "HIT", what is the reason for calling WordPress. If "HIT", what is the file used (URL).
- X-Rocket-Nginx-File: If "HIT", what is the file used (path on disk).
Check out the following links for more information:
- Licence info: https://github.com/SatelliteWP/rocket-n ... license.md
- SatelliteWP: A faster WordPress site with Rocket-Nginx 3.0: https://www.satellitewp.com/en/a-faster ... nginx-3-0/