Configure NGINX for WP Rocket

WP Rocket cache plugin is too familiar, but to better support the nginx VPS, it is impossible not to mention Rocket-Nginx.

SatelliteWP - WordPress Maintenance

Rocket-Nginx allows NGINX to directly distribute previously cached files without calling WordPress or any PHP. It also adds the headers to CSS, JS, and the browser’s cached images.

If you’re using Ubuntu + webinoly, get started now. The other platforms are similar.
To customize this tutorial, see the original article at: https://aznet.io/t/cau-hinh-nginx-cho-wp-rocket/100/1

1. Install Rocket-nginx

Why do I do this step first? Because you have finished installing and do nothing, it will not affect your website at all.

Using Mobaxterm makes it convenient

To install, you can:

cd /etc/nginx
git clone https://github.com/satellitewp/rocket-nginx.git

As of version 2.0, profiles must be created. To create the default configuration, you must rename the disabled ini file and run the configuration parser:

cd rocket-nginx
cp rocket-nginx.ini.disabled rocket-nginx.ini
php rocket-parser.php

This will generate configuration default.conf that can be included for all sites. If you need to change the default configuration, you can edit the ini file and add another section at the bottom of the file.
At this point, if you decide to continue… then come on

2. Turn off WordPress’s default Cron and run it manually

To disable WordPress cron job add the following line to your wp-config.php: define('DISABLE_WP_CRON', true);

Then do the cron job manually every 15 minutes, you can change this number like 5 or 10… (I used the first one):

*/15 * * * * wget -q -O - https://example.com/wp-cron.php?doing_wp_cron &>/dev/null

or

*/15 * * * * curl https://example.com/wp-cron.php?doing_wp_cron &>/dev/null

or

*/15 * * * * cd /home/user/public_html; php wp-cron.php &>/dev/null

Run the command:

crontab -e

Copy one of the lines above and paste it at the bottom of the table. To save, press Ctrl + x and Enter.

Make sure to check that your tasks are still running after this change!

See also: How to run WP Cron with Multisite

3. Configure for wordpress site

You need to apply rocket nginx to any website, just create a config file like this:

  • Directory access /var/www/example.com/
  • Create file rocket-nginx.conf with the content: include /etc/nginx/rocket-nginx/default.conf;

Or add a profile to your website at /etc/nginx/sites-available, you need to change your configuration:

server {
  ...
  # Rocket-Nginx configuration
  include rocket-nginx/default.conf;
    ...
}

Before you reload your configuration make sure you test it: nginx -t
After the test is done, you must reload your configuration service nginx reload

If you want to temporarily disable rocket-nginx, just rename the file rocket-nginx.conf to rocket-nginx.conf.bak and reload the configuration.

4. Configure rocket-nginx (optional)

You can customize something in the file rocket-nginx.ini (/etc/nginx/rocket-nginx/) such as: enable debugging, add the title Is-NewSection

When you edit the ini file, you must recreate your Nginx configuration file by running the parser:

cd /etc/nginx/rocket-nginx/
php rocket-parser.php

Newly added or modified sections will then generate an updated configuration file (*.conf) – default is default.conf.

Finally, each time you create (or recreate) the configuration files, you must:

  1. Test it to make sure it doesn’t generate any errors: nginx -t
  2. Reload configuration: service nginx reload

5 Check website activity

You access the website administration page, the WP-Rocket Plugin performs Clear cache and Preaload the cache again.

Next you go to the website and press F12, select the Network tab = > Headers to check = > you notice the line strong, X-Rocket-Nginx-Bypass: Yes is successfully configured.

Update: The current Rocket nginx version should show up x-rocket-nginx-serving-static: Yes

If strong, X-Rocket-Nginx-Bypass: No don’t worry too much, go to incognito mode or open another browser that you are not logged in yet then go back / Refresh to see if you switch from No → Yes.

Tags:

DATVNN.COM
Logo