Skip to content

Commit

Permalink
Offload file serving to NGINX
Browse files Browse the repository at this point in the history
  • Loading branch information
jimsihk authored Jun 7, 2024
1 parent 646c79a commit f2468ca
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions rootfs/docker-entrypoint-init.d/02-configure-moodle.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions rootfs/etc/nginx/conf.d/default/server/moodle.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit f2468ca

Please sign in to comment.