mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-27 15:54:03 +02:00
Fix: split fpm-uri flag in socket and url flag (#5364)
fixes #5249 (cherry picked from commit 85621487e86a400fd650e6797804ebadc6c9ec92)
This commit is contained in:
parent
67ff0546c0
commit
cdc60466b1
@ -102,7 +102,11 @@ class ConfigCommand extends Command
|
||||
*
|
||||
* --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-url=<url> Address where to pass requests to FPM [127.0.0.1:9000]
|
||||
*
|
||||
* --fpm-uri=<uri> Alias for --fpm-url
|
||||
*
|
||||
* --fpm-socket-path=<socketpath> Socket path where to pass requests to FPM, overrides --fpm-url
|
||||
*
|
||||
* --config=<directory> Path to Icinga Web 2's configuration files [/etc/icingaweb2]
|
||||
*
|
||||
@ -120,9 +124,13 @@ class ConfigCommand extends Command
|
||||
* icingacli setup config webserver apache \
|
||||
* --file=/etc/apache2/conf.d/icingaweb2.conf
|
||||
*
|
||||
* icingacli setup config webserver apache \
|
||||
* --file=/etc/apache2/conf.d/icingaweb2.conf
|
||||
* --fpm-url=localhost:9000
|
||||
*
|
||||
* icingacli setup config webserver nginx \
|
||||
* --root=/usr/share/icingaweb2/public \
|
||||
* --fpm-uri=unix:/var/run/php5-fpm.sock
|
||||
* --fpm-socket-path=/var/run/php8.3-fpm.sock
|
||||
*/
|
||||
public function webserverAction()
|
||||
{
|
||||
@ -157,10 +165,18 @@ class ConfigCommand extends Command
|
||||
|
||||
$enableFpm = $this->params->shift('enable-fpm', $webserver->getEnableFpm());
|
||||
|
||||
$fpmUri = trim($this->params->get('fpm-uri', $webserver->getFpmUri()));
|
||||
if (empty($fpmUri)) {
|
||||
$fpmSocketPath = trim($this->params->get('fpm-socket-path', $webserver->getFpmSocketPath()));
|
||||
$fpmUrl = trim($this->params->get('fpm-url', $webserver->getFpmUrl()));
|
||||
if (empty($fpmUrl)) {
|
||||
$fpmUrl = trim($this->params->get('fpm-uri', $webserver->getFpmUrl()));
|
||||
}
|
||||
if (empty($fpmSocketPath) && empty($fpmUrl)) {
|
||||
$this->fail($this->translate(
|
||||
'The argument --fpm-uri expects an address or path where to pass requests to FPM'
|
||||
'One of the arguments --fpm-socket-path or --fpm-url must be set to pass requests to FPM'
|
||||
));
|
||||
} elseif (!empty($fpmSocketPath) && !empty($fpmUrl)) {
|
||||
$this->fail($this->translate(
|
||||
'Only one of the arguments --fpm-socket-path or --fpm-url must be set to pass requests to FPM'
|
||||
));
|
||||
}
|
||||
$webserver
|
||||
@ -168,7 +184,8 @@ class ConfigCommand extends Command
|
||||
->setConfigDir($configDir)
|
||||
->setUrlPath($urlPath)
|
||||
->setEnableFpm($enableFpm)
|
||||
->setFpmUri($fpmUri);
|
||||
->setFpmUrl($fpmUrl)
|
||||
->setFpmSocketPath($fpmSocketPath);
|
||||
$config = $webserver->generate() . "\n";
|
||||
if (($file = $this->params->get('file')) !== null) {
|
||||
if (file_exists($file) === true) {
|
||||
|
@ -33,11 +33,25 @@ abstract class Webserver
|
||||
protected $configDir;
|
||||
|
||||
/**
|
||||
* Address or path where to pass requests to FPM
|
||||
* Address where to pass requests to FPM
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $fpmUri;
|
||||
protected $fpmUrl;
|
||||
|
||||
/**
|
||||
* Socket path where to pass requests to FPM
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $fpmSocketPath;
|
||||
|
||||
/**
|
||||
* FPM socket connection schema
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $fpmSocketSchema = 'unix:';
|
||||
|
||||
/**
|
||||
* Enable to pass requests to FPM
|
||||
@ -72,6 +86,7 @@ abstract class Webserver
|
||||
public function generate()
|
||||
{
|
||||
$template = $this->getTemplate();
|
||||
$fpmUri = $this->createFpmUri();
|
||||
|
||||
$searchTokens = array(
|
||||
'{urlPath}',
|
||||
@ -85,7 +100,7 @@ abstract class Webserver
|
||||
$this->getDocumentRoot(),
|
||||
preg_match('~/$~', $this->getUrlPath()) ? $this->getDocumentRoot() . '/' : $this->getDocumentRoot(),
|
||||
$this->getConfigDir(),
|
||||
$this->getFpmUri()
|
||||
$fpmUri
|
||||
);
|
||||
$template = str_replace($searchTokens, $replaceTokens, $template);
|
||||
return $template;
|
||||
@ -98,6 +113,13 @@ abstract class Webserver
|
||||
*/
|
||||
abstract protected function getTemplate();
|
||||
|
||||
/**
|
||||
* Creates the connection string for the respective web server
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract protected function createFpmUri();
|
||||
|
||||
/**
|
||||
* Set the URL path of Icinga Web 2
|
||||
*
|
||||
@ -208,25 +230,47 @@ abstract class Webserver
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the address or path where to pass requests to FPM
|
||||
* Get the address where to pass requests to FPM
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFpmUri()
|
||||
public function getFpmUrl()
|
||||
{
|
||||
return $this->fpmUri;
|
||||
return $this->fpmUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the address or path where to pass requests to FPM
|
||||
* Set the address where to pass requests to FPM
|
||||
*
|
||||
* @param string $uri
|
||||
* @param string $url
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setFpmUri($uri)
|
||||
public function setFpmUrl($url)
|
||||
{
|
||||
$this->fpmUri = (string) $uri;
|
||||
$this->fpmUrl = (string) $url;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the socket path where to pass requests to FPM
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFpmSocketPath()
|
||||
{
|
||||
return $this->fpmSocketPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the socket path where to pass requests to FPM
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setFpmSocketPath($socketPath)
|
||||
{
|
||||
$this->fpmSocketPath = (string) $socketPath;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
@ -10,7 +10,21 @@ use Icinga\Module\Setup\Webserver;
|
||||
*/
|
||||
class Apache extends Webserver
|
||||
{
|
||||
protected $fpmUri = '127.0.0.1:9000';
|
||||
protected $fpmUrl = '127.0.0.1:9000';
|
||||
|
||||
protected $fpmUrlSchema = 'fcgi://';
|
||||
|
||||
protected function createFpmUri()
|
||||
{
|
||||
$apacheFpmUri = "";
|
||||
if (empty($this->fpmSocketPath)) {
|
||||
$apacheFpmUri = $this->fpmUrlSchema . $this->fpmUrl;
|
||||
} else {
|
||||
$apacheFpmUri = $this->fpmSocketSchema . $this->fpmSocketPath . '|' . $this->fpmUrlSchema . 'localhost';
|
||||
}
|
||||
|
||||
return $apacheFpmUri;
|
||||
}
|
||||
|
||||
protected function getTemplate()
|
||||
{
|
||||
@ -23,7 +37,7 @@ Alias {urlPath} "{aliasDocumentRoot}"
|
||||
# # Forward PHP requests to FPM
|
||||
# SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
|
||||
# <LocationMatch "^{urlPath}/(.*\.php)$">
|
||||
# ProxyPassMatch "fcgi://{fpmUri}/{documentRoot}/$1"
|
||||
# ProxyPassMatch "{fpmUri}/{documentRoot}/$1"
|
||||
# </LocationMatch>
|
||||
#</IfVersion>
|
||||
|
||||
@ -71,7 +85,7 @@ Alias {urlPath} "{aliasDocumentRoot}"
|
||||
# # Forward PHP requests to FPM
|
||||
# SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
|
||||
# <FilesMatch "\.php$">
|
||||
# SetHandler "proxy:fcgi://{fpmUri}"
|
||||
# SetHandler "proxy:{fpmUri}"
|
||||
# ErrorDocument 503 {urlPath}/error_unavailable.html
|
||||
# </FilesMatch>
|
||||
# </IfVersion>
|
||||
@ -85,7 +99,7 @@ Alias {urlPath} "{aliasDocumentRoot}"
|
||||
# Forward PHP requests to FPM
|
||||
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
|
||||
<LocationMatch "^{urlPath}/(.*\.php)$">
|
||||
ProxyPassMatch "fcgi://{fpmUri}/{documentRoot}/$1"
|
||||
ProxyPassMatch "{fpmUri}/{documentRoot}/$1"
|
||||
</LocationMatch>
|
||||
</IfVersion>
|
||||
|
||||
@ -131,7 +145,7 @@ Alias {urlPath} "{aliasDocumentRoot}"
|
||||
# Forward PHP requests to FPM
|
||||
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
|
||||
<FilesMatch "\.php$">
|
||||
SetHandler "proxy:fcgi://{fpmUri}"
|
||||
SetHandler "proxy:{fpmUri}"
|
||||
ErrorDocument 503 {urlPath}/error_unavailable.html
|
||||
</FilesMatch>
|
||||
</IfVersion>
|
||||
|
@ -10,10 +10,15 @@ use Icinga\Module\Setup\Webserver;
|
||||
*/
|
||||
class Nginx extends Webserver
|
||||
{
|
||||
protected $fpmUri = '127.0.0.1:9000';
|
||||
protected $fpmUrl = '127.0.0.1:9000';
|
||||
|
||||
protected $enableFpm = true;
|
||||
|
||||
protected function createFpmUri()
|
||||
{
|
||||
return empty($this->fpmSocketPath) ? $this->fpmUrl : $this->fpmSocketSchema . $this->fpmSocketPath;
|
||||
}
|
||||
|
||||
protected function getTemplate()
|
||||
{
|
||||
return <<<'EOD'
|
||||
|
Loading…
x
Reference in New Issue
Block a user