Configure Varnish (TM) for WordPress
NOTE: The steps below assume that WordPress is already running at the root URL of the server, such as at http://wordpress.example.com/, and that Varnish ™ is enabled. Varnish ™ is disabled by default, but you can enable it by following the instructions in our Varnish ™ guide.
Download the different files used in the example:
Nginx
Follow these steps:
- Log in to the server console using SSH.
Backup the Varnish ™ configuration file:
$ sudo cp /opt/bitnami/varnish/etc/varnish/default.vcl /opt/bitnami/varnish/etc/varnish/default.vcl.backup
Add the WordPress-specific Varnish ™ configuration by executing the following commands:
$ sudo cp wordpress.vcl /opt/bitnami/varnish/etc/varnish/default.vcl $ sudo sed -i 's/port\s*=\s*"[^"]*"/port = "80"/g' /opt/bitnami/varnish/etc/varnish/default.vcl
Restart Varnish ™:
$ sudo /opt/bitnami/ctlscript.sh restart varnish
Check if your website is being served properly by Varnish ™ on port 81 by adding :81 to the domain name in your browser.
If Varnish ™ is working correctly, switch the Nginx and Varnish ™ ports and activate Varnish ™ on port 80:
$ sudo sed -i 's/listen .*80;$/listen 81;/g' /opt/bitnami/nginx/conf/bitnami/bitnami.conf $ sudo sed -i 's/=80/=81/g' /opt/bitnami/properties.ini $ sudo sed -i 's/port\s*=\s*"[^"]*"/port = "81"/g' /opt/bitnami/varnish/etc/varnish/default.vcl $ sudo sed -i 's/VARNISH_PORT=.*$/VARNISH_PORT=80/g' /opt/bitnami/varnish/scripts/ctl.sh $ sudo /opt/bitnami/ctlscript.sh restart
Varnish is a registered trademark of Varnish Software AB and its affiliates.