diff --git a/rootfs/docker-entrypoint-init.d/02-configure-moodle.sh b/rootfs/docker-entrypoint-init.d/02-configure-moodle.sh index b2a4730..78c4384 100755 --- a/rootfs/docker-entrypoint-init.d/02-configure-moodle.sh +++ b/rootfs/docker-entrypoint-init.d/02-configure-moodle.sh @@ -93,6 +93,12 @@ if [ ! -f "${WEB_PATH}"/config.php ]; then fi #'readonly' => [ 'instance' => ['dbhost' => 'slave.dbhost', 'dbport' => '', 'dbuser' => '', 'dbpass' => '']] + # Offload the file serving from PHP process + # shellcheck disable=SC2016 + sed -i '/require_once/i $CFG->xsendfile = '\''X-Accel-Redirect'\'';' "${WEB_PATH}"/config.php + # shellcheck disable=SC2016 + sed -i '/require_once/i $CFG->xsendfilealiases = array('\''\/dataroot\/'\'' => $CFG->dataroot);' "${WEB_PATH}"/config.php + if [ "$SSLPROXY" = 'true' ]; then # shellcheck disable=SC2016 sed -i '/require_once/i $CFG->sslproxy = true;' "${WEB_PATH}"/config.php diff --git a/rootfs/etc/nginx/conf.d/default/server/moodle.conf b/rootfs/etc/nginx/conf.d/default/server/moodle.conf index df3151e..4b85765 100644 --- a/rootfs/etc/nginx/conf.d/default/server/moodle.conf +++ b/rootfs/etc/nginx/conf.d/default/server/moodle.conf @@ -13,3 +13,10 @@ deny all; return 404; } + + # Offload the file serving from PHP process as per https://docs.moodle.org/404/en/Nginx#XSendfile_aka_X-Accel-Redirect + # Adjust based on https://moodle.org/mod/forum/discuss.php?d=413492#p1715955 to fix broken images + location ~ ^/dataroot/(.*)$ { + internal; + alias /var/www/moodledata/$1; + }