Enabling Google Cloud CDN in front of Moodle requires coordinated configuration across three layers:
- Moodle (
config.php): Must emit revisioned path-based URLs ($CFG->slasharguments = true;) for static theme and JavaScript assets. - NGINX (
nginx.conf/nginx.conf-template):- Must forward
PATH_INFO(fastcgi_param PATH_INFO $fastcgi_path_info;) to PHP-FPM so Moodle's revisioned PHP asset loaders (/theme/styles.php,/theme/image.php,/theme/font.php,/theme/javascript.php,/lib/javascript.php,/lib/requirejs.php) resolve their slash arguments. - Must strip
Set-Cookieheaders (fastcgi_hide_header Set-Cookie;) and emitCache-Control: "public, max-age=31536000, immutable"on public versioned Moodle asset loaders—because Google Cloud CDN refuses to cache any HTTP response that includes aSet-Cookieheader. - Must force
Cache-Control: "private, no-store, no-cache, must-revalidate"on authenticated endpoints (/pluginfile.php,/draftfile.php,/tokenpluginfile.php,/webservice/pluginfile.php,/repository/,/login/) so private student submissions, course files, and login sessions are never cached at the CDN edge.
- Must forward
- GKE
BackendConfig(6-backendconfig/ingress-backendconfig-nginx.yamland6-backendconfig/ingress-backendconfig-nginx-uploads.yaml):- The main
ingress-backendconfigusescacheMode: USE_ORIGIN_HEADERS(withincludeHost: true,includeProtocol: true,includeQueryString: true,negativeCaching: false, andserveWhileStale: 86400), ensuring Cloud CDN strictly honors theCache-Controlheaders emitted by NGINX rather than blindly caching.pdfor image URLs served through/pluginfile.php. - The dedicated uploads backend (
ingress-backendconfig-uploads) disables Cloud CDN (cdn.enabled: false) and extendstimeoutSec: 3600to support large file uploads (/repository/repository_ajax.php,/repository/draftfiles_ajax.php, and/webservice/upload.php).
- The main
- Streaming 10 GB+ File Uploads without RAM Overhead (
5a-deployment-no-helm/moodle-deployment-nginx-uploads.yaml):- Disk-Backed
/tmp(emptyDir: { sizeLimit: 15Gi }): Standard web pods mount/tmpwithmedium: Memory(tmpfs) for ultra-fast local caching ofX-Accel-Redirectstatic assets. Onmoodle-deployment-uploads,/tmpuses node SSD ephemeral storage instead ofmedium: Memoryso 10 GB multipart temporary files (/tmp/phpXXXXXX) never consume container RAM or triggerOOMKilled. - Zero Duplicate Buffering (
fastcgi_request_buffering off;): NGINX streams upload chunks directly to PHP-FPM over the Unix domain socket without writing a duplicate 10 GB copy to/tmp/nginx/client_temp. - Single-Upload Concurrency & Queueing (
PHP_FPM_MAX_CHILDREN: "1"+listen.backlog = 128): Each upload pod processes 1 heavy upload at a time at full disk/network throughput while queueing additional concurrent uploads in the socket backlog (or scaling out viamoodle-uploads-hpa).
- Disk-Backed
| Endpoint Pattern | Handled By | Set-Cookie Header |
Cache-Control Header |
Cloud CDN Behavior |
|---|---|---|---|---|
/theme/styles.php/<theme>/<rev>/all |
NGINX -> PHP-FPM | Stripped (fastcgi_hide_header Set-Cookie) |
public, max-age=31536000, immutable |
Cached at Edge (1 year; busted automatically on Moodle theme revision change) |
/theme/image.php, /theme/font.php, /theme/javascript.php |
NGINX -> PHP-FPM | Stripped (fastcgi_hide_header Set-Cookie) |
public, max-age=31536000, immutable |
Cached at Edge |
/lib/javascript.php/<rev>/..., /lib/requirejs.php/<rev>/... |
NGINX -> PHP-FPM | Stripped (fastcgi_hide_header Set-Cookie) |
public, max-age=31536000, immutable |
Cached at Edge |
Static files (*.jpg, *.png, *.css, *.js, *.woff2, *.svg) |
NGINX directly | None | public, max-age=2592000 |
Cached at Edge (30 days) |
/pluginfile.php/..., /draftfile.php/..., /tokenpluginfile.php/... |
NGINX -> PHP-FPM (+ X-Accel-Redirect) |
Preserved | private, no-store, no-cache, must-revalidate |
Never cached by Cloud CDN |
/repository/repository_ajax.php, /repository/draftfiles_ajax.php |
Routed to moodle-service-uploads (ingress-backendconfig-uploads) |
Preserved | private, no-store, no-cache, must-revalidate |
Bypassed (cdn.enabled: false, timeoutSec: 3600) |
- Apply both
BackendConfigresources (main web traffic with Cloud CDN + dedicated uploads without Cloud CDN):
kubectl apply -f 6-backendconfig/ingress-backendconfig-nginx.yaml
kubectl apply -f 6-backendconfig/ingress-backendconfig-nginx-uploads.yaml- Apply the main and dedicated upload ConfigMaps, Deployments, Services, and HPAs:
kubectl apply -f 5a-deployment-no-helm/moodle-configmap-nginx.yaml
kubectl apply -f 5a-deployment-no-helm/moodle-configmap-nginx-uploads.yaml
kubectl apply -f 5a-deployment-no-helm/moodle-deployment-nginx.yaml
kubectl apply -f 5a-deployment-no-helm/moodle-deployment-nginx-uploads.yaml
kubectl apply -f 5a-deployment-no-helm/moodle-service.yaml
kubectl apply -f 5a-deployment-no-helm/moodle-service-uploads.yaml
kubectl apply -f 9-hpa/moodle-hpa.yaml
kubectl apply -f 9-hpa/moodle-uploads-hpa.yaml- Apply the Ingress resource (
8-ingress/gce-ingress-external.yaml), which routes/repository/repository_ajax.phpand/repository/draftfiles_ajax.phptomoodle-service-uploadsand all other traffic (/*) tomoodle:
kubectl apply -f 8-ingress/gce-ingress-external.yamlOnce the Google Cloud Load Balancer and Ingress are provisioned, verify that Moodle's revisioned theme/JS endpoints return Cache-Control: public, max-age=31536000, immutable without Set-Cookie and produce Age / cache-hit headers from Cloud CDN:
curl -I "https://moodle.<YOUR-LB-EXTERNAL-IP>.nip.io/theme/styles.php/boost/1/all"And verify that authenticated file endpoints emit Cache-Control: private, no-store, no-cache, must-revalidate:
curl -I "https://moodle.<YOUR-LB-EXTERNAL-IP>.nip.io/pluginfile.php"