Skip to content

Commit d2e59c8

Browse files
Merge pull request #2944 from craigcomstock/ENT-11440/master
ENT-11440: Enable http2 in Mission Portal webserver
2 parents 75d54b2 + a94548d commit d2e59c8

File tree

8 files changed

+816
-2
lines changed

8 files changed

+816
-2
lines changed

cfe_internal/enterprise/mission_portal.cf

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,56 @@
11
bundle agent cfe_internal_enterprise_mission_portal
22
{
33
meta:
4-
54
"description" string => "Manage mission portal configuration";
65

6+
classes:
7+
"mission_portal_http2_enabled"
8+
expression => and(
9+
fileexists("$(sys.workdir)/httpd/php/sbin/php-fpm"),
10+
fileexists("$(sys.workdir)/httpd/modules/mod_http2.so")
11+
),
12+
scope => "namespace", # so it is visible in datastate() used in httpd.conf template rendering in bundle cfe_internal_enterprise_mission_portal_apache
13+
comment => "If php-fpm and mod_http2.so are present then http2 is enabled
14+
and we use this class in httpd.conf to configure accordingly.";
15+
vars:
16+
policy_server.enterprise_edition.mission_portal_http2_enabled::
17+
"php_fpm_pid_file" string => "$(sys.workdir)/httpd/php-fpm.pid";
18+
"php_fpm_www_pool_max_children" string => ifelse(
19+
isvariable("default:def.php_fpm_www_pool_max_children"),
20+
"$(default:def.php_fpm_www_pool_max_children)",
21+
"60");
22+
"php_fpm_www_pool_start_servers" string => ifelse(
23+
isvariable("default:def.php_fpm_www_pool_start_servers"),
24+
"$(default:def.php_fpm_www_pool_start_servers)",
25+
"50");
26+
"php_fpm_www_pool_min_spare_servers" string => ifelse(
27+
isvariable("default:def.php_fpm_www_pool_min_spare_servers"),
28+
"$(default:def.php_fpm_www_pool_min_spare_servers)",
29+
"40");
30+
"php_fpm_www_pool_max_spare_servers" string => ifelse(
31+
isvariable("default:def.php_fpm_www_pool_max_spare_servers"),
32+
"$(default:def.php_fpm_www_pool_max_spare_servers)",
33+
"50");
34+
"php_fpm_state" data => mergedata(
35+
'{"vars": { "sys": { "workdir": "${default:sys.workdir}" } } }',
36+
'{
37+
"max_children":"${php_fpm_www_pool_max_children}",
38+
"start_servers":"${php_fpm_www_pool_start_servers}",
39+
"min_spare_servers":"${php_fpm_www_pool_min_spare_servers}",
40+
"max_spare_servers":"${php_fpm_www_pool_max_spare_servers}"
41+
}');
42+
43+
reports:
44+
DEBUG::
45+
"Using variable default:def.php_fpm_www_pool_max_children: ${default:def.php_fpm_www_pool_max_children} instead of built-in default"
46+
if => isvariable("default:def.php_fpm_www_pool_max_children");
47+
"Using variable default:def.php_fpm_www_pool_start_servers: ${default:def.php_fpm_www_pool_start_servers} instead of built-in default"
48+
if => isvariable("default:def.php_fpm_www_pool_start_servers");
49+
"Using variable default:def.php_fpm_www_pool_min_spare_servers: ${default:def.php_fpm_www_pool_min_spare_servers} instead of built-in default"
50+
if => isvariable("default:def.php_fpm_www_pool_min_spare_servers");
51+
"Using variable default:def.php_fpm_www_pool_max_spare_servers: ${default:def.php_fpm_www_pool_max_spare_servers} instead of built-in default"
52+
if => isvariable("default:def.php_fpm_www_pool_max_spare_servers");
53+
754
methods:
855

956
policy_server::
@@ -20,7 +67,23 @@ bundle agent cfe_internal_enterprise_mission_portal
2067
handle => "cfe_internal_management_update_cli_rest_server_url_config",
2168
comment => "Update the REST server URL port in the Mission Portal when cfe_internal_hub_vars.https_port is changed";
2269

70+
policy_server.mission_portal_http2_enabled::
71+
"PHP FastCGI process manager"
72+
usebundle => service_config(
73+
"cf-php-fpm",
74+
"$(this.promise_dirname)/templates/php-fpm.conf.mustache",
75+
"$(sys.workdir)/httpd/php/etc/php-fpm.conf",
76+
"$(sys.workdir)/httpd/php/sbin/php-fpm -t --fpm-config ",
77+
@(php_fpm_state),
78+
"$(php_fpm_pid_file)"
79+
);
80+
81+
services:
82+
policy_server.mission_portal_http2_enabled::
83+
"cf-php-fpm"
84+
service_policy => "start";
2385
}
86+
2487
bundle agent apachectl_patched_for_upgrade
2588
# @brief Ensure that apacehctl is patched so that it is able to re-start services
2689
#

cfe_internal/enterprise/templates/httpd.conf.mustache

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,12 @@ DocumentRoot "{{{vars.cfe_internal_hub_vars.public_docroot}}}"
110110
</FilesMatch>
111111

112112
ErrorLog "logs/error_log"
113+
{{#data:cfengine_enterprise_mission_portal_debug_php_fpm}}
114+
LogLevel warn rewrite:trace6 proxy:debug proxy_fcgi:debug dir:debug
115+
{{/data:cfengine_enterprise_mission_portal_debug_php_fpm}}
116+
{{^data:cfengine_enterprise_mission_portal_debug_php_fpm}}
113117
LogLevel warn
118+
{{/data:cfengine_enterprise_mission_portal_debug_php_fpm}}
114119

115120
<IfModule log_config_module>
116121
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
@@ -244,10 +249,26 @@ LogLevel warn
244249
</IfModule>
245250

246251

252+
{{#classes.mission_portal_http2_enabled}}
253+
# Use mod_http2
254+
LoadModule http2_module modules/mod_http2.so
255+
# Prefer http2 protocol
256+
Protocols h2 h2c http/1.1
257+
258+
# Setup php to be handled by php-fpm. Required for use of mod_http2 due to threading issues in php.
259+
LoadModule proxy_module modules/mod_proxy.so
260+
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
261+
# Need to pass auth headers to fpm
262+
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
263+
<FilesMatch \.php$>
264+
SetHandler "proxy:fcgi://127.0.0.1:9000"
265+
</FilesMatch>
266+
{{/classes.mission_portal_http2_enabled}}
267+
{{^classes.mission_portal_http2_enabled}}
247268
LoadModule php{{{vars.cfe_internal_hub_vars.php_version}}}_module modules/libphp{{{vars.cfe_internal_hub_vars.php_version}}}.so
248269
AddHandler php{{{vars.cfe_internal_hub_vars.php_version}}}-script .php
249270
AddType application/x-httpd-php-source php{{{vars.cfe_internal_hub_vars.php_version}}}
250-
271+
{{/classes.mission_portal_http2_enabled}}
251272

252273
<Directory "{{{vars.cfe_internal_hub_vars.public_docroot}}}">
253274

0 commit comments

Comments
 (0)