Skip to content
Draft
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
24 changes: 23 additions & 1 deletion cfe_internal/enterprise/mission_portal.cf
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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"
Expand Down
36 changes: 35 additions & 1 deletion cfe_internal/enterprise/templates/httpd.conf.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -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

<Directory "{{{vars.cfe_internal_hub_vars.public_docroot}}}">
# Carabiner bundles in tmp/ get a new name whenever a source file changes
<If "%{REQUEST_URI} =~ m#^/tmp/#">
Header set Cache-Control "public, max-age=31536000, immutable"
</If>
<FilesMatch "\.(woff2?|ttf|eot|otf|png|jpe?g|gif|svg|ico)$">
Header set Cache-Control "public, max-age=604800"
</FilesMatch>
</Directory>

{{#classes.mission_portal_http2_enabled}}
# Use mod_http2
LoadModule http2_module modules/mod_http2.so
Expand All @@ -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
<FilesMatch \.php$>
SetHandler "proxy:fcgi://127.0.0.1:9000"
SetHandler "proxy:unix:{{{vars.sys.workdir}}}/httpd/php-fpm.sock|fcgi://localhost"
</FilesMatch>
{{/classes.mission_portal_http2_enabled}}
{{^classes.mission_portal_http2_enabled}}
Expand Down Expand Up @@ -298,6 +313,18 @@ AddType application/x-httpd-php-source php{{{vars.cfe_internal_hub_vars.php_v
</IfModule>
</Directory>

# 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"
<Location "/api">
<If "%{HTTPS} != 'on' && %{REMOTE_ADDR} !~ /^(127\.0\.0\.1|::1)$/">
Require all denied
</If>
<If "%{HTTPS} != 'on'">
SetEnvIf Remote_Addr "^(127\.0\.0\.1|::1)$" HTTPS=on
</If>
</Location>

<Directory "{{{vars.cfe_internal_hub_vars.docroot}}}/api">

Order deny,allow
Expand All @@ -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]
</IfModule>
{{#classes.mission_portal_http2_enabled}}

# Mission Portal requests wait on API requests, so the API gets its own php-fpm pool.
<FilesMatch \.php$>
SetHandler "proxy:unix:{{{vars.sys.workdir}}}/httpd/php-fpm-api.sock|fcgi://localhost"
</FilesMatch>
{{/classes.mission_portal_http2_enabled}}
</Directory>

<Directory "{{{vars.cfe_internal_hub_vars.docroot}}}/api/static">
Expand Down
20 changes: 19 additions & 1 deletion cfe_internal/enterprise/templates/php-fpm.conf.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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.
Expand Down Expand Up @@ -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}}}
Loading