Skip to main content

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).

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โ€‹

  1. Go to cloudflare.com and sign up for a free account.
  2. Click Add a Site and enter your journal domain.
  3. Select the Free plan (sufficient for most journals).

Step 2 โ€” Update Your DNSโ€‹

  1. Cloudflare will scan your existing DNS records.
  2. Review and confirm the detected records.
  3. Cloudflare provides two nameserver addresses (e.g., alice.ns.cloudflare.com).
  4. Log in to your domain registrar and replace your existing nameservers with the Cloudflare nameservers.
  5. DNS propagation takes 5โ€“60 minutes.

Step 3 โ€” Configure Cloudflare Settings for OJSโ€‹

  1. In Cloudflare, go to SSL/TLS โ†’ set to Full (strict) if your server has a valid SSL certificate, or Flexible if it does not.
  2. Go to Caching โ†’ Configuration:
    • Caching level: Standard
    • Browser Cache TTL: 4 hours
  3. 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:

  1. In Cloudflare, go to Rules โ†’ Cache Rules.
  2. Add a rule to Bypass Cache for:
    URI path contains /index.php
    or more specifically:
    URI 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
info

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:

  1. Open your journal in a browser.
  2. Use browser developer tools (Network tab) and check the response headers.
  3. Look for cf-cache-status: HIT (Cloudflare) or X-Cache: Hit to confirm CDN caching is active.
  4. Test load times from different regions using GTmetrix or WebPageTest.

Troubleshootingโ€‹

ProblemSolution
OJS admin panel broken after CloudflareAdd cache bypass rules for /index.php paths
SSL errors after Cloudflare setupSwitch SSL mode to Full (strict) or ensure your origin has a valid certificate
Files not loading from CDNVerify DNS has propagated; check Cloudflare SSL settings
Submission uploads failingEnsure POST requests to OJS are not being cached or blocked by Cloudflare

Next Stepsโ€‹