Tutorial: CDN Setup for OJS
Role: Site Administrator
Time: 30โ60 minutes
OJS Version: 3.5+
A Content Delivery Network (CDN) distributes your journal's static assets (CSS, JavaScript, images, PDFs) from servers around the world, reducing load times for international readers and decreasing the load on your origin server.
Before You Startโ
- You have root or sudo access to the OJS server.
- You control your domain's DNS settings.
- You have decided on a CDN provider (Cloudflare recommended for ease of setup).
Option A โ Cloudflare CDN (Recommended โ Free Tier Available)โ
Cloudflare acts as a reverse-proxy CDN that sits in front of your entire domain. It is the easiest to set up.
Step 1 โ Create a Cloudflare Accountโ
- Go to cloudflare.com and sign up for a free account.
- Click Add a Site and enter your journal domain.
- Select the Free plan (sufficient for most journals).
Step 2 โ Update Your DNSโ
- Cloudflare will scan your existing DNS records.
- Review and confirm the detected records.
- Cloudflare provides two nameserver addresses (e.g.,
alice.ns.cloudflare.com). - Log in to your domain registrar and replace your existing nameservers with the Cloudflare nameservers.
- DNS propagation takes 5โ60 minutes.
Step 3 โ Configure Cloudflare Settings for OJSโ
- In Cloudflare, go to SSL/TLS โ set to Full (strict) if your server has a valid SSL certificate, or Flexible if it does not.
- Go to Caching โ Configuration:
- Caching level: Standard
- Browser Cache TTL: 4 hours
- Go to Speed โ Optimization:
- Enable Auto Minify for JavaScript, CSS, and HTML (optional โ test on staging first).
Step 4 โ Add a Cache Exclusion for OJS Adminโ
OJS's admin dashboard and submission system must not be cached:
- In Cloudflare, go to Rules โ Cache Rules.
- Add a rule to Bypass Cache for:
or more specifically:URI path contains /index.phpURI contains /admin or URI contains /login or URI contains /submission
Option B โ Nginx + External CDN (Advanced)โ
For servers using Nginx, you can serve static assets from a CDN bucket (e.g., Amazon CloudFront, BunnyCDN):
Step 1 โ Configure OJS to Use a CDN URLโ
In config.inc.php:
; CDN URL for static assets
cdn_base_url = https://cdn.yourdomain.com
OJS does not have native CDN URL rewriting. This option requires custom Nginx configuration or a reverse-proxy setup to serve /public/ files from the CDN.
Step 2 โ Sync Static Files to CDN Storageโ
Use rsync or your CDN's storage sync tools to copy OJS public files:
rsync -av /path/to/ojs/public/ /path/to/cdn-bucket/
Verifying CDN Performanceโ
After setup:
- Open your journal in a browser.
- Use browser developer tools (Network tab) and check the response headers.
- Look for
cf-cache-status: HIT(Cloudflare) orX-Cache: Hitto confirm CDN caching is active. - Test load times from different regions using GTmetrix or WebPageTest.
Troubleshootingโ
| Problem | Solution |
|---|---|
| OJS admin panel broken after Cloudflare | Add cache bypass rules for /index.php paths |
| SSL errors after Cloudflare setup | Switch SSL mode to Full (strict) or ensure your origin has a valid certificate |
| Files not loading from CDN | Verify DNS has propagated; check Cloudflare SSL settings |
| Submission uploads failing | Ensure POST requests to OJS are not being cached or blocked by Cloudflare |
Next Stepsโ
- Server Configuration โ PHP and server performance settings
- Security Hardening โ use Cloudflare WAF for additional security
- Webmaster Tools โ CDN and performance monitoring tools overview