Third-Party Software Notice
Our support team cannot provide support for third-party software and services. However, if you need assistance or spot an issue with this article please post in the vCanopy Community Forum, and we will make necessary updates/improvements where needed.
Swift Performance is a solid caching plugin – right up there at the top of the heap alongside WP Rocket in terms of caching plugin performance.
While neither of these can compete with server-level caching in terms of performance or handling concurrent users, they can still produce excellent results on our stack.
That all said, Swift Performance can actually integrate with Nginx Helper according to their documentation, although this comes at a cost. You can also add their Rewrite Rules directly to an Nginx configuration file
Swift Performance, Nginx Helper, and Custom Headers
Swift Performance does integrate with Nginx Helper according to their documentation:
“Swift Performance supports Nginx Helper. If you install and configure Nginx Helper properly, Swift will clear Nginx/FastCGI/Redis when cache was cleared in Swift”
https://swiftperformance.io/faq/nginx-fastcgi-redis-support/
However, this does come at a cost – you can’t use custom headers. The following information is from a vCanopy user who was in contact with their support:
Keeping existing headers is available only with Disk cache + PHP for Nginx.
With Disk cache + Rewrites is available only for Apache.
The following paragraph is taken directly from their documentation (source link below):
“Keep Original Headers – If you are using a plugin which send custom headers you can keep them for the cached version as well. Some security plugins add nosniff response header and some other headers-. With this feature you can keep your original headers. This feature is available only in Pro version.”
https://swiftperformance.io/documentation/swift-settings-caching-tab/
Using Disk Cache + Rewrites with vCanopy
As mentioned above, if you choose to use this option you won’t be able to use custom headers.
If you’re cool with that, then below is how to add Swift’s Rewrite rules to your website via Nginx.
STEP 1. SSH INTO YOUR SERVER:
Please see the following articles to get started:
Generate your SSH Key:
Generate SSH Key on Windows with Putty
Generate SSH Key on Windows with Windows Subsystem for Linux
Generate SSH Key on Windows with Windows CMD/PowerShell
Add your SSH Key to vCanopy:
Add/Remove an SSH Key to/from an Active vCanopy Server
Connect to your server:
Connect to a vCanopy server by SSH as Root user.
STEP 2. CONFIGURE SWIFT PERFORMANCE
First, head to Dashboard > Settings > Swift Performance
Then click through to the settings page, click caching in the left hand sidebar, and select Disk Cache with Rewrites from the dropdown. Save the changes.
These may change as you change your settings (e.g. adding a specific page
###BEGIN Swift Performance### set $swift_cache 1; if ($request_method = POST){ set $swift_cache 0; } if ($args != ''){ set $swift_cache 0; } if ($http_cookie ~* "(wordpress_logged_in)") { set $swift_cache 0; } if ($request_uri ~ ^/wp-content/cache/swift-performance/([^/]*)/assetproxy) { set $swift_cache 0; } if (!-f "/var/www/site.url/htdocs/wp-content/cache/swift-performance//$http_host/$request_uri/desktop/unauthenticated/index.html") { set $swift_cache 0; } if ($swift_cache = 1){ rewrite .* /wp-content/cache/swift-performance/$http_host/$request_uri/desktop/unauthenticated/index.html last; } location ~ desktop/unauthenticated/index.html { add_header Link "</wp-content/cache/swift-performance/$http_host$request_uri/css/desktop-full.css>; rel=preload; as=style,</wp-content/cache/swift-performance/$http_host$request_uri/js/desktop-scripts.js>; rel=preload; as=script"; } ###END Swift Performance###
STEP 3. CREATE YOUR CONFIG
We’ll be creating a file called “swift-main-context.conf”. Run the following command switching out “site.url” for your website’s domain:
nano /var/www/site.url/nginx/swift-main-context.conf
Ctrl+O and then hit enter. Then Ctrl+X to exit nano.
STEP 4. CHECK AND RESTART NGINX
We now need to test our Nginx syntax with:
nginx -t
If there are no errors present, reload nginx with the following command:
gp ngx reload
Your rewrite rules are now active.