mirror of
https://github.com/moodle/moodle.git
synced 2025-04-15 13:33:52 +02:00
MDL-26028 implement Nginx X-Sendfile directory aliases setting
This commit is contained in:
parent
7e9f1b63e5
commit
f7d26a0545
@ -225,6 +225,16 @@ $CFG->admin = 'admin';
|
||||
// $CFG->xsendfile = 'X-Sendfile'; // Apache {@see https://tn123.org/mod_xsendfile/}
|
||||
// $CFG->xsendfile = 'X-LIGHTTPD-send-file'; // Lighttpd {@see http://redmine.lighttpd.net/projects/lighttpd/wiki/X-LIGHTTPD-send-file}
|
||||
// $CFG->xsendfile = 'X-Accel-Redirect'; // Nginx {@see http://wiki.nginx.org/XSendfile}
|
||||
// If your X-Sendfile implementation (usually Nginx) uses directory aliases specify them
|
||||
// in the following array setting:
|
||||
// $CFG->xsendfilealiases = array(
|
||||
// '/dataroot/' => $CFG->dataroot,
|
||||
// '/cachedir/' => '/var/www/moodle/cache', // for custom $CFG->cachedir locations
|
||||
// '/tempdir/' => '/var/www/moodle/temp', // for custom $CFG->tempdir locations
|
||||
// '/filedir' => '/var/www/moodle/filedir', // for custom $CFG->filedir locations
|
||||
// );
|
||||
//
|
||||
//
|
||||
//
|
||||
// This setting will prevent the 'My Courses' page being displayed when a student
|
||||
// logs in. The site front page will always show the same (logged-out) view.
|
||||
|
@ -47,19 +47,30 @@ function xsendfile($filepath) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$filepath = realpath($filepath);
|
||||
|
||||
$aliased = false;
|
||||
if (!empty($CFG->xsendfilealiases) and is_array($CFG->xsendfilealiases)) {
|
||||
foreach ($CFG->xsendfilealiases as $alias=>$dir) {
|
||||
$dir = realpath($dir).PATH_SEPARATOR;
|
||||
if (strpos($filepath, $dir) === 0) {
|
||||
$filepath = $alias.substr($filepath, strlen($dir));
|
||||
$aliased = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($CFG->xsendfile === 'X-LIGHTTPD-send-file') {
|
||||
// http://redmine.lighttpd.net/projects/lighttpd/wiki/X-LIGHTTPD-send-file says 1.4 it does not support byteserving
|
||||
header('Accept-Ranges: none');
|
||||
|
||||
} else if ($CFG->xsendfile === 'X-Accel-Redirect') {
|
||||
// http://wiki.nginx.org/XSendfile
|
||||
// Nginx is using relative path to protected folder, please note you can not use cache dir, tempdir and file pool outside of dataroot!
|
||||
$filepath = realpath($filepath);
|
||||
$dataroot = realpath($CFG->dataroot);
|
||||
if (strpos($filepath, $dataroot) !== 0) {
|
||||
// Nginx requires paths relative to aliases, you need to specify them in config.php
|
||||
if (!$aliased) {
|
||||
return false;
|
||||
}
|
||||
$filepath = substr($filepath, strlen($dataroot));
|
||||
}
|
||||
|
||||
header("$CFG->xsendfile: $filepath");
|
||||
|
Loading…
x
Reference in New Issue
Block a user