Setup: Add --enable-fpm flag

This commit is contained in:
Michael Friedrich 2018-12-21 15:29:06 +01:00
parent 08c879249b
commit 26c6ce3e55
4 changed files with 97 additions and 1 deletions

View File

@ -99,6 +99,8 @@ class ConfigCommand extends Command
* --root|--document-root=<directory> The directory from which the webserver will serve files * --root|--document-root=<directory> The directory from which the webserver will serve files
* [/path/to/icingaweb2/public] * [/path/to/icingaweb2/public]
* *
* --enable-fpm Enable FPM handler for Apache (Nginx is always enabled)
*
* --fpm-uri=<uri> Address or path where to pass requests to FPM [127.0.0.1:9000] * --fpm-uri=<uri> Address or path where to pass requests to FPM [127.0.0.1:9000]
* *
* --config=<directory> Path to Icinga Web 2's configuration files [/etc/icingaweb2] * --config=<directory> Path to Icinga Web 2's configuration files [/etc/icingaweb2]
@ -119,6 +121,7 @@ class ConfigCommand extends Command
* *
* icingacli setup config webserver nginx \ * icingacli setup config webserver nginx \
* --root=/usr/share/icingaweb2/public \ * --root=/usr/share/icingaweb2/public \
* --enable-fpm
* --fpm-uri=unix:/var/run/php5-fpm.sock * --fpm-uri=unix:/var/run/php5-fpm.sock
*/ */
public function webserverAction() public function webserverAction()
@ -149,6 +152,9 @@ class ConfigCommand extends Command
'The argument --config expects a path to Icinga Web 2\'s configuration files' 'The argument --config expects a path to Icinga Web 2\'s configuration files'
)); ));
} }
$enableFpm = $this->params->shift('enable-fpm', $webserver->getEnableFpm());
$fpmUri = trim($this->params->get('fpm-uri', $webserver->getFpmUri())); $fpmUri = trim($this->params->get('fpm-uri', $webserver->getFpmUri()));
if (empty($fpmUri)) { if (empty($fpmUri)) {
$this->fail($this->translate( $this->fail($this->translate(
@ -159,6 +165,7 @@ class ConfigCommand extends Command
->setDocumentRoot($documentRoot) ->setDocumentRoot($documentRoot)
->setConfigDir($configDir) ->setConfigDir($configDir)
->setUrlPath($urlPath) ->setUrlPath($urlPath)
->setEnableFpm($enableFpm)
->setFpmUri($fpmUri); ->setFpmUri($fpmUri);
$config = $webserver->generate() . "\n"; $config = $webserver->generate() . "\n";
if (($file = $this->params->get('file')) !== null) { if (($file = $this->params->get('file')) !== null) {

View File

@ -174,6 +174,30 @@ abstract class Webserver
return $this->configDir; return $this->configDir;
} }
/**
* Get whether FPM is enabled
*
* @return bool
*/
public function getEnableFpm()
{
return $this->enableFpm;
}
/**
* Set FPM enabled
*
* @param bool $flag
*
* @return $this
*/
public function setEnableFpm($flag)
{
$this->enableFpm = (bool) $flag;
return $this;
}
/** /**
* Get the address or path where to pass requests to FPM * Get the address or path where to pass requests to FPM
* *

View File

@ -11,9 +11,11 @@ use Icinga\Module\Setup\Webserver;
class Apache extends Webserver class Apache extends Webserver
{ {
protected $fpmUri = 'fcgi://127.0.0.1:9000'; protected $fpmUri = 'fcgi://127.0.0.1:9000';
protected $enableFpm = false;
protected function getTemplate() protected function getTemplate()
{ {
if (! $this->enableFpm) {
return <<<'EOD' return <<<'EOD'
Alias {urlPath} "{documentRoot}" Alias {urlPath} "{documentRoot}"
@ -22,7 +24,7 @@ Alias {urlPath} "{documentRoot}"
# # Forward PHP requests to FPM # # Forward PHP requests to FPM
# SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1 # SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
# <LocationMatch "^{urlPath}/(.*\.php)$"> # <LocationMatch "^{urlPath}/(.*\.php)$">
# ProxyPassMatch "fcgi://127.0.0.1:9000/{documentRoot}/$1" # ProxyPassMatch "fcgi://{fpmUri}/{documentRoot}/$1"
# </LocationMatch> # </LocationMatch>
#</IfVersion> #</IfVersion>
@ -76,5 +78,66 @@ Alias {urlPath} "{documentRoot}"
# </IfVersion> # </IfVersion>
</Directory> </Directory>
EOD; EOD;
} else {
return <<<'EOD'
Alias {urlPath} "{documentRoot}"
<IfVersion < 2.4>
# Forward PHP requests to FPM
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
<LocationMatch "^{urlPath}/(.*\.php)$">
ProxyPassMatch "fcgi://{fpmUri}/{documentRoot}/$1"
</LocationMatch>
</IfVersion>
<Directory "{documentRoot}">
Options SymLinksIfOwnerMatch
AllowOverride None
DirectoryIndex index.php
<IfModule mod_authz_core.c>
# Apache 2.4
<RequireAll>
Require all granted
</RequireAll>
</IfModule>
<IfModule !mod_authz_core.c>
# Apache 2.2
Order allow,deny
Allow from all
</IfModule>
SetEnv ICINGAWEB_CONFIGDIR "{configDir}"
EnableSendfile Off
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase {urlPath}/
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
</IfModule>
<IfModule !mod_rewrite.c>
DirectoryIndex error_norewrite.html
ErrorDocument 404 {urlPath}/error_norewrite.html
</IfModule>
<IfVersion >= 2.4>
# Forward PHP requests to FPM
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
<FilesMatch "\.php$">
SetHandler "proxy:{fpmUri}"
ErrorDocument 503 {urlPath}/error_unavailable.html
</FilesMatch>
</IfVersion>
</Directory>
EOD;
}
} }
} }

View File

@ -12,6 +12,8 @@ class Nginx extends Webserver
{ {
protected $fpmUri = '127.0.0.1:9000'; protected $fpmUri = '127.0.0.1:9000';
protected $enableFpm = true;
protected function getTemplate() protected function getTemplate()
{ {
return <<<'EOD' return <<<'EOD'