diff --git a/cfe_internal/enterprise/mission_portal.cf b/cfe_internal/enterprise/mission_portal.cf
index 665c8f457e..c420214fb7 100644
--- a/cfe_internal/enterprise/mission_portal.cf
+++ b/cfe_internal/enterprise/mission_portal.cf
@@ -70,7 +70,7 @@ bundle agent cfe_internal_enterprise_mission_portal
"fpm_children_average_memory_kb" int => "25600";
# average memory taken by one fpm process 25MB * 1024
- "php_fpm_www_pool_max_children_calculated"
+ "php_fpm_www_pool_max_children_by_memory"
int => int(
ifelse(
isvariable("mem_total_kb"),
@@ -81,6 +81,28 @@ bundle agent cfe_internal_enterprise_mission_portal
)
);
+ # More workers than this per CPU core only add CPU contention and database connections.
+ "php_fpm_www_pool_max_children_by_cpu"
+ int => int(
+ ifelse(
+ isvariable("cpu_cores_number"),
+ eval("$(cpu_cores_number) * 12"),
+ "60"
+ )
+ );
+
+ "php_fpm_www_pool_max_children_calculated"
+ int => int(
+ ifelse(
+ isgreaterthan(
+ "$(php_fpm_www_pool_max_children_by_memory)",
+ "$(php_fpm_www_pool_max_children_by_cpu)"
+ ),
+ "$(php_fpm_www_pool_max_children_by_cpu)",
+ "$(php_fpm_www_pool_max_children_by_memory)"
+ )
+ );
+
"php_fpm_pid_file" string => "$(sys.workdir)/httpd/php-fpm.pid";
"php_fpm_www_pool_max_children"
diff --git a/cfe_internal/enterprise/templates/httpd.conf.mustache b/cfe_internal/enterprise/templates/httpd.conf.mustache
index d2fe8bdf27..c804dce009 100644
--- a/cfe_internal/enterprise/templates/httpd.conf.mustache
+++ b/cfe_internal/enterprise/templates/httpd.conf.mustache
@@ -252,6 +252,21 @@ LogLevel warn
# Timeout defaults to 60 but that is too short for some operations on slower hub hardware
Timeout 120
+# Compress text responses, Mission Portal loads several megabytes of JavaScript per page
+LoadModule filter_module modules/mod_filter.so
+LoadModule deflate_module modules/mod_deflate.so
+AddOutputFilterByType DEFLATE text/html text/plain text/css text/javascript application/javascript application/json image/svg+xml
+
+
+ # Carabiner bundles in tmp/ get a new name whenever a source file changes
+
+ Header set Cache-Control "public, max-age=31536000, immutable"
+
+
+ Header set Cache-Control "public, max-age=604800"
+
+
+
{{#classes.mission_portal_http2_enabled}}
# Use mod_http2
LoadModule http2_module modules/mod_http2.so
@@ -264,7 +279,7 @@ LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
# Need to pass auth headers to fpm
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
-SetHandler "proxy:fcgi://127.0.0.1:9000"
+SetHandler "proxy:unix:{{{vars.sys.workdir}}}/httpd/php-fpm.sock|fcgi://localhost"
{{/classes.mission_portal_http2_enabled}}
{{^classes.mission_portal_http2_enabled}}
@@ -298,6 +313,18 @@ AddType application/x-httpd-php-source php{{{vars.cfe_internal_hub_vars.php_v
+# Mission Portal calls the local API over plain HTTP to avoid TLS on every request. Outside the HTTPS
+# virtual host /api is only served to localhost, and those requests act for HTTPS clients.
+Alias "/api" "{{{vars.cfe_internal_hub_vars.docroot}}}/api"
+
+
+ Require all denied
+
+
+ SetEnvIf Remote_Addr "^(127\.0\.0\.1|::1)$" HTTPS=on
+
+
+
Order deny,allow
@@ -309,6 +336,13 @@ AddType application/x-httpd-php-source php{{{vars.cfe_internal_hub_vars.php_v
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.php [QSA,L]
+{{#classes.mission_portal_http2_enabled}}
+
+ # Mission Portal requests wait on API requests, so the API gets its own php-fpm pool.
+
+ SetHandler "proxy:unix:{{{vars.sys.workdir}}}/httpd/php-fpm-api.sock|fcgi://localhost"
+
+{{/classes.mission_portal_http2_enabled}}
diff --git a/cfe_internal/enterprise/templates/php-fpm.conf.mustache b/cfe_internal/enterprise/templates/php-fpm.conf.mustache
index 3a1ba166b4..8103351a52 100644
--- a/cfe_internal/enterprise/templates/php-fpm.conf.mustache
+++ b/cfe_internal/enterprise/templates/php-fpm.conf.mustache
@@ -179,7 +179,7 @@ group = cfapache
; (IPv6 and IPv4-mapped) on a specific port;
; '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
-listen = 127.0.0.1:9000
+listen = {{{vars.sys.workdir}}}/httpd/php-fpm.sock
; Set listen(2) backlog.
; Default Value: 511 (-1 on Linux, FreeBSD and OpenBSD)
@@ -194,6 +194,9 @@ listen = 127.0.0.1:9000
;listen.owner = nobody
;listen.group = nobody
;listen.mode = 0660
+listen.owner = cfapache
+listen.group = cfapache
+listen.mode = 0660
; When POSIX Access Control Lists are supported you can set them using
; these options, value is a comma separated list of user/group names.
@@ -632,3 +635,18 @@ access.log = {{{vars.sys.workdir}}}/httpd/logs/www-pool.access.log
;php_admin_value[error_log] = /var/log/fpm-php.www.log
;php_admin_flag[log_errors] = on
;php_admin_value[memory_limit] = 32M
+
+; Mission Portal workers wait on loopback API requests. With one shared pool, all workers can end up
+; waiting for API requests that have no free worker left, so the API runs in its own pool.
+[api]
+user = cfapache
+group = cfapache
+listen = {{{vars.sys.workdir}}}/httpd/php-fpm-api.sock
+listen.owner = cfapache
+listen.group = cfapache
+listen.mode = 0660
+pm = dynamic
+pm.max_children = {{{max_children}}}
+pm.start_servers = {{{start_servers}}}
+pm.min_spare_servers = {{{min_spare_servers}}}
+pm.max_spare_servers = {{{max_spare_servers}}}