1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
|
<?php
/* Icinga Web 2 | (c) 2014 Icinga Development Team | GPLv2+ */
namespace Icinga\Module\Setup\Webserver;
use Icinga\Module\Setup\Webserver;
/**
* Generate Apache 2.x configuration
*/
class Apache extends Webserver
{
protected $fpmUrl = '127.0.0.1:9000';
protected $fpmUrlSchema = 'fcgi://';
protected function createFpmUri()
{
return empty($this->fpmSocketPath)
? $this->fpmUrlSchema . $this->fpmUrl
: $this->fpmSocketSchema . $this->fpmSocketPath . '|' . $this->fpmUrlSchema . 'localhost';
}
protected function getTemplate()
{
if (! $this->enableFpm) {
return <<<'EOD'
Alias {urlPath} "{aliasDocumentRoot}"
# Remove comments if you want to use PHP FPM and your Apache version is older than 2.4
#<IfVersion < 2.4>
# # Forward PHP requests to FPM
# SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
# <LocationMatch "^{urlPath}/(.*\.php)$">
# ProxyPassMatch "{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>
# Remove comments if you want to use PHP FPM and your Apache version
# is greater than or equal to 2.4
# <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;
} else {
return <<<'EOD'
Alias {urlPath} "{aliasDocumentRoot}"
<IfVersion < 2.4>
# Forward PHP requests to FPM
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
<LocationMatch "^{urlPath}/(.*\.php)$">
ProxyPassMatch "{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;
}
}
}
|