Skip to content

Commit

Permalink
Added moodle.conf nginx configuration file to avoid some direct files (
Browse files Browse the repository at this point in the history
  • Loading branch information
erseco authored Feb 23, 2025
1 parent 8568a33 commit f6f3ebc
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions rootfs/etc/nginx/server-conf.d/moodle.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# This passes 404 pages to Moodle so they can be themed
error_page 404 /error/index.php;
error_page 403 =404 /error/index.php;

# Dedicated block to override error_page for any /fixtures/ requests
location ~ /fixtures/ {
deny all;
return 404;
}


# TODO: Temporary block exact match for /privacy/tests/fixtures/logo.png (see issue #74)
location = /privacy/tests/fixtures/logo.png {
deny all;
return 404;
}

# TODO: Temporary block exact match for /enrol/lti/tests/fixtures/input.xml (see issue #74)
location = /enrol/lti/tests/fixtures/input.xml {
deny all;
return 404;
}

# Block exact match for /admin/environment.xml
location = /admin/environment.xml {
deny all;
return 404;
}

# Block exact match for /lib/db/install.xml
location = /lib/db/install.xml {
deny all;
return 404;
}

# Block exact match for /mod/assign/db/install.xml
location = /mod/assign/db/install.xml {
deny all;
return 404;
}

# Hide all dot files but allow "Well-Known URIs" as per RFC 5785
location ~ /\.(?!well-known).* {
return 404;
}

# This should be after the php fpm rule and very close to the last nginx ruleset.
# Don't allow direct access to various internal files. See MDL-69333
location ~ (/vendor/|/node_modules/|composer\.json|/readme|/README|readme\.txt|README\.txt|upgrade\.txt|UPGRADING\.md|UPGRADING\-CURRENT\.md|db/install\.xml|/fixtures/|/behat/|phpunit\.xml|\.lock|environment\.xml|doesnotexist|CHANGELOG|CHANGELOG\.md|TRADEMARK\.txt|PULL_REQUEST_TEMPLATE\.txt|INSTALL\.txt|CONTRIBUTING\.txt|behat\.yml\.dist|phpunit\.xml\.dist|package\.json|npm-shrinkwrap\.json|security\.txt|index\.php\.inc) {
deny all;
return 404;
}

# Offload file serving from PHP process as per Moodle documentation
location ~ ^/dataroot/(.*)$ {
internal;
alias /var/www/moodledata/$1;
}

0 comments on commit f6f3ebc

Please sign in to comment.