Skip to content

Commit 3858903

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

4 files changed

Lines changed: 68 additions & 19 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/index.php -f
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/index.php -f
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/index.php !-f
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/index.php !-f
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: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
include totara/server.conf;
22

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

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

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

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

2528
fastcgi_param PATH_INFO $fastcgi_path_info;
26-
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
2729
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
2830

31+
# For v21+ installs (public/ webroot), route all PHP through the front controller.
32+
set $script_filename $document_root$fastcgi_script_name;
33+
if ($use_front_controller) {
34+
set $script_filename $document_root/index.php;
35+
}
36+
fastcgi_param SCRIPT_FILENAME $script_filename;
37+
2938
fastcgi_buffers 16 16k;
3039
fastcgi_buffer_size 32k;
3140
}

nginx/config/remote-server.conf

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +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).
33+
# For v13-20 installs the real script exists under server/ and is served directly.
34+
try_files $uri $uri/ /index.php?$query_string;
3135
}
3236

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

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

5256
fastcgi_param PATH_INFO $fastcgi_path_info;
53-
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
5457
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
5558

59+
# For v21+ installs (public/ webroot), route all PHP through the front controller.
60+
set $script_filename $document_root$fastcgi_script_name;
61+
if ($use_front_controller) {
62+
set $script_filename $document_root/index.php;
63+
}
64+
fastcgi_param SCRIPT_FILENAME $script_filename;
65+
5666
fastcgi_buffers 16 16k;
5767
fastcgi_buffer_size 32k;
5868
}
@@ -68,4 +78,4 @@ location ~ .*\.(txt|md|json|xml|mustache)$ {
6878
location ~ ^/lib/yui/build/moodle-core-checknet/assets/checknet.txt$ {
6979
allow all;
7080
}
71-
}
81+
}

nginx/config/server.conf

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,28 @@ 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+
set $use_front_controller 0;
35+
set $rootdir $base_rootdir;
36+
3437
# If we have the server directory (version 13 and newer) use this as the wwwroot
3538
if (-f "$rootdir/server/version.php") {
3639
# in which case, set that directory as the root
37-
set $rootdir "$rootdir/server";
40+
set $rootdir $base_rootdir/server;
41+
}
42+
43+
44+
# If we have the public directory (version 21 and newer) it is a sibling of server/,
45+
# so check from the original sitename root. Re-check against REMOTE_SRC base.
46+
# We use a separate variable to avoid double-appending on the server/ branch.
47+
if (-f $base_rootdir/public/index.php) {
48+
set $rootdir $base_rootdir/public;
49+
set $use_front_controller 1;
3850
}
3951

4052
root $rootdir;

0 commit comments

Comments
 (0)