Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 27 additions & 9 deletions apache/conf.d/server.conf
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,41 @@ RewriteEngine on

DocumentRoot "$REMOTE_SRC"

# Direct php requests to the php-X.X container
RewriteCond %{HTTP_HOST} totara(\d)(\d)(|\.behat)(|\.localhost)(:[0-9]+)?$
# Direct php requests to the php-X.X container.
# Hostname format: [sitename.]totara{major}{minor}[.behat][.debug][.localhost]
# Apply non-debug first, then override with debug if the host contains .debug.
RewriteCond %{HTTP_HOST} totara(\d)(\d)(\.behat)?(\.localhost)?(:[0-9]+)?$
RewriteRule \.php - [H=proxy:fcgi://php-%1.%2:9000]

# Direct xdebug requests to the php-X.X-debug container
RewriteCond %{HTTP_HOST} totara(\d)(\d)(|\.behat)\.debug(|\.localhost)(:[0-9]+)?$
# Override: direct Xdebug requests to the php-X.X-debug container
RewriteCond %{HTTP_HOST} totara(\d)(\d)(\.behat)?\.debug(\.localhost)?(:[0-9]+)?$
RewriteRule \.php - [H=proxy:fcgi://php-%1.%2-debug:9000]

# Handle if the site name is specified in the host, e.g. sitename.totara73
RewriteCond %{HTTP_HOST} ^(.+)\.totara(|\.localhost)
RewriteRule ^(.*)$ - [E=SITENAME:%1]
# Capture the optional sitename prefix from the hostname.
# Matches: sitename.totara84, sitename.totara84.localhost, sitename.totara84.debug, etc.
RewriteCond %{HTTP_HOST} ^([\w-]+)\.totara\d
RewriteRule ^ - [E=SITENAME:%1]

# If the server directory exists, then rewrite it to use it
# v21+ (public/ directory exists): route all requests through the front controller.
# The [H=proxy:...] flag is set here (not only for .php URLs) so that requests like /
# or static-looking URLs are also processed by PHP-FPM via public/index.php.
RewriteCond %{HTTP_HOST} totara(\d)(\d)
RewriteCond %{HTTP_HOST} !\.debug
RewriteCond %{DOCUMENT_ROOT}/%{ENV:SITENAME}/public/index.php -f
RewriteRule ^ %{DOCUMENT_ROOT}/%{ENV:SITENAME}/public/index.php [QSA,L,H=proxy:fcgi://php-%1.%2:9000]

# v21+ (debug variant): same but routes to the debug PHP-FPM container
RewriteCond %{HTTP_HOST} totara(\d)(\d).*\.debug
RewriteCond %{DOCUMENT_ROOT}/%{ENV:SITENAME}/public/index.php -f
RewriteRule ^ %{DOCUMENT_ROOT}/%{ENV:SITENAME}/public/index.php [QSA,L,H=proxy:fcgi://php-%1.%2-debug:9000]

# If the server directory exists (version 13 to 20), rewrite to use it
RewriteCond %{DOCUMENT_ROOT}/%{ENV:SITENAME}/public/index.php !-f
RewriteCond %{DOCUMENT_ROOT}/%{ENV:SITENAME}/server/version.php -f
RewriteRule ^(.*)$ %{DOCUMENT_ROOT}/%{ENV:SITENAME}/server$1 [QSA]

# Otherwise don't use the server directory
# Otherwise (version 12 and older) don't use a subdirectory
RewriteCond %{DOCUMENT_ROOT}/%{ENV:SITENAME}/public/index.php !-f
RewriteCond %{DOCUMENT_ROOT}/%{ENV:SITENAME}/server/version.php !-f
RewriteRule ^(.*)$ %{DOCUMENT_ROOT}/%{ENV:SITENAME}$1 [QSA]

Expand Down
15 changes: 12 additions & 3 deletions nginx/config/local-server.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
include totara/server.conf;


# Here you can define how you want nginx to handle requests made from your local network.
# You can do whatever you want here.

Expand All @@ -9,7 +8,11 @@ include totara/server.conf;
client_max_body_size 1G;

location / {
autoindex on;
# Redirect non-existing files to index.php for "pretty" URLs
# For v21+ installs (public/ webroot), all PHP requests are routed through
# public/index.php (the front controller).
# For v13-20 installs the real script exists under server/ and is served directly.
try_files $uri $uri/ /index.php?$query_string;
}

location ~ [^/]\.php(/|$) {
Expand All @@ -23,9 +26,15 @@ location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+\.php)(/.+)$;

fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;

# For v21+ installs (public/ webroot), route all PHP through the front controller.
set $script_filename $document_root$fastcgi_script_name;
if ($use_front_controller) {
set $script_filename $document_root/index.php;
}
fastcgi_param SCRIPT_FILENAME $script_filename;

fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
}
Expand Down
18 changes: 14 additions & 4 deletions nginx/config/remote-server.conf
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,18 @@ error_page 403 =404 /404.html;
error_page 501 502 503 =500 /500.html;

location / {
try_files $uri $uri/ =404;
# Redirect non-existing files to index.php for "pretty" URLs
# For v21+ installs (public/ webroot), all PHP requests are routed through
# public/index.php (the front controller).
# For v13-20 installs the real script exists under server/ and is served directly.
try_files $uri $uri/ /index.php?$query_string;
}

location ~ ^.*\/(cli|tests|db|classes|amd\/src|rb_sources|yui\/src)\/.*$ {
deny all;
}

if (!-f "$document_root/version.php") {
if (!-f $base_rootdir/server/version.php) {
# No version.php exists, so the site isn't set up properly or the forwarding host is incorrect
return 404;
}
Expand All @@ -50,9 +54,15 @@ location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+\.php)(/.+)$;

fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;

# For v21+ installs (public/ webroot), route all PHP through the front controller.
set $script_filename $document_root$fastcgi_script_name;
if ($use_front_controller) {
set $script_filename $document_root/index.php;
}
fastcgi_param SCRIPT_FILENAME $script_filename;

fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
}
Expand All @@ -68,4 +78,4 @@ location ~ .*\.(txt|md|json|xml|mustache)$ {
location ~ ^/lib/yui/build/moodle-core-checknet/assets/checknet.txt$ {
allow all;
}
}
}
18 changes: 15 additions & 3 deletions nginx/config/server.conf
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,28 @@ if ($debug = "debug") {
}

# Default root
set $rootdir "$REMOTE_SRC";
set $base_rootdir "$REMOTE_SRC";

if ($sitename != "") {
set $rootdir "$rootdir/$sitename";
set $base_rootdir $base_rootdir/$sitename;
}

set $use_front_controller 0;
set $rootdir $base_rootdir;

# If we have the server directory (version 13 and newer) use this as the wwwroot
if (-f "$rootdir/server/version.php") {
# in which case, set that directory as the root
set $rootdir "$rootdir/server";
set $rootdir $base_rootdir/server;
}


# If we have the public directory (version 21 and newer) it is a sibling of server/,
# so check from the original sitename root. Re-check against REMOTE_SRC base.
# We use a separate variable to avoid double-appending on the server/ branch.
if (-f $base_rootdir/public/index.php) {
set $rootdir $base_rootdir/public;
set $use_front_controller 1;
}

root $rootdir;
Expand Down
Loading