From 23e00a4a249c5b99500ed8e9b5a37bbdecd600a6 Mon Sep 17 00:00:00 2001 From: jimsihk <99048231+jimsihk@users.noreply.github.com> Date: Sun, 30 Jun 2024 18:48:15 +0800 Subject: [PATCH] Allow controlling xsendfile to nginx --- Dockerfile | 5 ++++- README.md | 3 ++- .../docker-entrypoint-init.d/02-configure-moodle.sh | 13 +++++++++---- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 46433f8..6df0962 100644 --- a/Dockerfile +++ b/Dockerfile @@ -58,6 +58,7 @@ ENV MOODLE_GIT_URL=${ARG_MOODLE_GIT_URL} \ DB_PREFIX=mdl_ \ DB_DBHANDLEOPTIONS=false \ SSLPROXY=false \ + REVERSEPROXY=false \ MOODLE_EMAIL=user@example.com \ MOODLE_LANGUAGE=en \ MOODLE_SITENAME=New-Site \ @@ -80,7 +81,9 @@ ENV MOODLE_GIT_URL=${ARG_MOODLE_GIT_URL} \ AUTO_UPDATE_MOODLE=true \ UPGRADE_MOODLE_CODE=true \ DISABLE_WEB_INSTALL_PLUGIN=false \ - MAINT_STATUS_KEYWORD='Status: enabled' + MAINT_STATUS_KEYWORD='Status: enabled' \ + DEBUG=false \ + XSENDFILE=true ARG ARG_REDISSENTINEL_PLUGIN_GIT_URL='https://github.com/catalyst/moodle-cachestore_redissentinel.git' ARG ARG_REDISSENTINEL_PLUGIN_GIT_BRANCH='master' diff --git a/README.md b/README.md index 52ea940..ededee6 100644 --- a/README.md +++ b/README.md @@ -137,12 +137,13 @@ Define the ENV variables in docker-compose.yml file | MAINT_STATUS_KEYWORD | Status: enabled | Keyword for detecting Moodle maintenance status when running admin/cli/maintenance.php, language following the Moodle site default language | | LOCAL_CACHE_DIRECTORY | | Set the path to a local fast filesystem for Moodle local caching that no need to be shared with other instances | | DEBUG | false | Enable debug mode | +| XSENDFILE | true | Set to false to disable offloading static file serving to NGINX [X-Accel-Redirect](https://docs.moodle.org/en/Nginx#XSendfile_aka_X-Accel-Redirect) | _More settings on PHP and NGINX can refer to the base image https://github.com/jimsihk/alpine-php-nginx/blob/dev/README.md_ ### Important Note about using `AUTO_UPDATE_MOODLE` and `UPDATE_MOODLE_CODE` -If set to `true`, Moodle will be set to [CLI maintenance mode](https://docs.moodle.org/401/en/Maintenance_mode#CLI_maintenance_mode) at container start while performing the update. No user will be able to use Moodle, not even admin. +If set to `true`, Moodle will be set to [CLI maintenance mode](https://docs.moodle.org/en/Maintenance_mode#CLI_maintenance_mode) at container start while performing the update. No user will be able to use Moodle, not even admin. If a cluster of Moodle containers are deployed for HA (e.g. on Kubernetes), it is suggested to set both to `false` to avoid unexpected interruption to users when auto scaling, such as adding extra containers to the cluster or container restart for auto healing. diff --git a/rootfs/docker-entrypoint-init.d/02-configure-moodle.sh b/rootfs/docker-entrypoint-init.d/02-configure-moodle.sh index d3cbbcc..6b05794 100755 --- a/rootfs/docker-entrypoint-init.d/02-configure-moodle.sh +++ b/rootfs/docker-entrypoint-init.d/02-configure-moodle.sh @@ -311,8 +311,10 @@ config_session_cache() { config_file_serving() { echo "Configuring file serving..." # Offload the file serving from PHP process - update_or_add_config_value "\$CFG->xsendfile" "X-Accel-Redirect" - update_or_add_config_value "\$CFG->xsendfilealiases['/dataroot/']" "\$CFG->dataroot" "noquote" + if [ -z "$XSENDFILE" ] || [ "$XSENDFILE" = true ]; then + update_or_add_config_value "\$CFG->xsendfile" "X-Accel-Redirect" + update_or_add_config_value "\$CFG->xsendfilealiases['/dataroot/']" "\$CFG->dataroot" "noquote" + fi if [ -n "$LOCAL_CACHE_DIRECTORY" ]; then if [ ! -d "$LOCAL_CACHE_DIRECTORY" ]; then @@ -320,13 +322,16 @@ config_file_serving() { mkdir -p "$LOCAL_CACHE_DIRECTORY" fi update_or_add_config_value "\$CFG->localcachedir" "$LOCAL_CACHE_DIRECTORY" - update_or_add_config_value "\$CFG->xsendfilealiases['/localcachedir/']" "$LOCAL_CACHE_DIRECTORY" - cat << EOL >> /etc/nginx/conf.d/default/server/moodle.conf + + if [ -z "$XSENDFILE" ] || [ "$XSENDFILE" = true ]; then + update_or_add_config_value "\$CFG->xsendfilealiases['/localcachedir/']" "$LOCAL_CACHE_DIRECTORY" + cat << EOL >> /etc/nginx/conf.d/default/server/moodle.conf location ~ ^/localcachedir/(.*)$ { internal; alias $LOCAL_CACHE_DIRECTORY/\$1; } EOL + fi echo "Set $LOCAL_CACHE_DIRECTORY as localcachedir" fi }