Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
integration
prechecker
Commits
f7d26a05
Commit
f7d26a05
authored
Apr 30, 2012
by
Petr Skoda
Browse files
MDL-26028 implement Nginx X-Sendfile directory aliases setting
parent
7e9f1b63
Changes
2
Hide whitespace changes
Inline
Side-by-side
config-dist.php
View file @
f7d26a05
...
...
@@ -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.
...
...
lib/xsendfilelib.php
View file @
f7d26a05
...
...
@@ -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
"
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment