Skip to content

Commit 205bace

Browse files
angelakuznetsovaNing Zhou
authored andcommitted
feat: update totara-docker-dev with support for the new entrypoint
1 parent 12689db commit 205bace

4 files changed

Lines changed: 71 additions & 25 deletions

File tree

apache/conf.d/server.conf

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,41 @@ RewriteEngine on
2222

2323
DocumentRoot "$REMOTE_SRC"
2424

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

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

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

37-
# If the server directory exists, then rewrite it to use it
40+
# v21+ (public/ directory exists): route all requests through the front controller.
41+
# The [H=proxy:...] flag is set here (not only for .php URLs) so that requests like /
42+
# or static-looking URLs are also processed by PHP-FPM via public/index.php.
43+
RewriteCond %{HTTP_HOST} totara(\d)(\d)
44+
RewriteCond %{HTTP_HOST} !\.debug
45+
RewriteCond %{DOCUMENT_ROOT}/%{ENV:SITENAME}/public -d
46+
RewriteRule ^ %{DOCUMENT_ROOT}/%{ENV:SITENAME}/public/index.php [QSA,L,H=proxy:fcgi://php-%1.%2:9000]
47+
48+
# v21+ (debug variant): same but routes to the debug PHP-FPM container
49+
RewriteCond %{HTTP_HOST} totara(\d)(\d).*\.debug
50+
RewriteCond %{DOCUMENT_ROOT}/%{ENV:SITENAME}/public -d
51+
RewriteRule ^ %{DOCUMENT_ROOT}/%{ENV:SITENAME}/public/index.php [QSA,L,H=proxy:fcgi://php-%1.%2-debug:9000]
52+
53+
# If the server directory exists (version 13 to 20), rewrite to use it
54+
RewriteCond %{DOCUMENT_ROOT}/%{ENV:SITENAME}/public !-d
3855
RewriteCond %{DOCUMENT_ROOT}/%{ENV:SITENAME}/server/version.php -f
3956
RewriteRule ^(.*)$ %{DOCUMENT_ROOT}/%{ENV:SITENAME}/server$1 [QSA]
4057

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

nginx/config/local-server.conf

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ include totara/server.conf;
99
client_max_body_size 1G;
1010

1111
location / {
12-
autoindex on;
12+
# Redirect non-existing files to index.php for "pretty" URLs
13+
# For v21+ installs (public/ webroot), all PHP requests are routed through
14+
# public/index.php (the front controller). The front controller reads
15+
# REQUEST_URI to dispatch to the correct script inside server/.
16+
# For v13-20 installs the real script exists under server/ and is served directly.
17+
try_files $uri $uri/ /index.php?$query_string;
1318
}
1419

1520
location ~ [^/]\.php(/|$) {
@@ -23,9 +28,15 @@ location ~ [^/]\.php(/|$) {
2328
fastcgi_split_path_info ^(.+\.php)(/.+)$;
2429

2530
fastcgi_param PATH_INFO $fastcgi_path_info;
26-
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
2731
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
2832

33+
# For v21+ installs (public/ websroot), route all PHP through the front controller.
34+
set $script_filename $document_root$fastcgi_script_name;
35+
if ($use_front_controller) {
36+
set $script_filename $document_root/index.php;
37+
}
38+
fastcgi_param SCRIPT_FILENAME $script_filename;
39+
2940
fastcgi_buffers 16 16k;
3041
fastcgi_buffer_size 32k;
3142
}

nginx/config/remote-server.conf

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,18 @@ error_page 403 =404 /404.html;
2727
error_page 501 502 503 =500 /500.html;
2828

2929
location / {
30-
try_files $uri $uri/ =404;
30+
# Redirect non-existing files to index.php for "pretty" URLs
31+
# For v21+ installs (public/ webroot), all PHP requests are routed through
32+
# public/index.php (the front controller). The front controller reads
33+
# REQUEST_URI to dispatch to the correct script inside server/.
34+
# For v13-20 installs the real script exists under server/ and is served directly.
35+
try_files $uri $uri/ /index.php?$query_string;
3136
}
3237

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

37-
if (!-f "$document_root/version.php") {
38-
# No version.php exists, so the site isn't set up properly or the forwarding host is incorrect
39-
return 404;
40-
}
41-
4242
location ~ [^/]\.php(/|$) {
4343
fastcgi_pass $upstream:9000;
4444
include fastcgi_params;
@@ -50,9 +50,15 @@ location ~ [^/]\.php(/|$) {
5050
fastcgi_split_path_info ^(.+\.php)(/.+)$;
5151

5252
fastcgi_param PATH_INFO $fastcgi_path_info;
53-
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
5453
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
5554

55+
# For v21+ installs (public/ webroot), route all PHP through the front controller.
56+
set $script_filename $document_root$fastcgi_script_name;
57+
if ($use_front_controller) {
58+
set $script_filename $document_root/index.php;
59+
}
60+
fastcgi_param SCRIPT_FILENAME $script_filename;
61+
5662
fastcgi_buffers 16 16k;
5763
fastcgi_buffer_size 32k;
5864
}
@@ -68,4 +74,4 @@ location ~ .*\.(txt|md|json|xml|mustache)$ {
6874
location ~ ^/lib/yui/build/moodle-core-checknet/assets/checknet.txt$ {
6975
allow all;
7076
}
71-
}
77+
}

nginx/config/server.conf

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,27 @@ if ($debug = "debug") {
2525
}
2626

2727
# Default root
28-
set $rootdir "$REMOTE_SRC";
28+
set $base_rootdir "$REMOTE_SRC";
2929

3030
if ($sitename != "") {
31-
set $rootdir "$rootdir/$sitename";
31+
set $base_rootdir "$base_rootdir/$sitename";
3232
}
3333

34-
# If we have the server directory (version 13 and newer) use this as the wwwroot
35-
if (-f "$rootdir/server/version.php") {
36-
# in which case, set that directory as the root
37-
set $rootdir "$rootdir/server";
34+
# Move this check from remote-server.conf
35+
if (!-f "$base_rootdir/server/version.php") {
36+
# No version.php exists, so the site isn't set up properly or the forwarding host is incorrect
37+
return 404;
38+
}
39+
40+
set $use_front_controller 0;
41+
set $rootdir "$base_rootdir/server";
42+
43+
# If we have the public directory (version 21 and newer) it is a sibling of server/,
44+
# so check from the original sitename root. Re-check against REMOTE_SRC base.
45+
# We use a separate variable to avoid double-appending on the server/ branch.
46+
if (-d "$base_rootdir/public") {
47+
set $rootdir "$base_rootdir/public";
48+
set $use_front_controller 1;
3849
}
3950

4051
root $rootdir;

0 commit comments

Comments
 (0)