Skip to content

Commit

Permalink
Allow controlling xsendfile to nginx
Browse files Browse the repository at this point in the history
  • Loading branch information
jimsihk committed Jun 30, 2024
1 parent 47a66a3 commit 23e00a4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ ENV MOODLE_GIT_URL=${ARG_MOODLE_GIT_URL} \
DB_PREFIX=mdl_ \
DB_DBHANDLEOPTIONS=false \
SSLPROXY=false \
REVERSEPROXY=false \
[email protected] \
MOODLE_LANGUAGE=en \
MOODLE_SITENAME=New-Site \
Expand All @@ -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'
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
13 changes: 9 additions & 4 deletions rootfs/docker-entrypoint-init.d/02-configure-moodle.sh
Original file line number Diff line number Diff line change
Expand Up @@ -311,22 +311,27 @@ 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
echo "Creating $LOCAL_CACHE_DIRECTORY for localcachedir..."
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
}
Expand Down

0 comments on commit 23e00a4

Please sign in to comment.