-
Notifications
You must be signed in to change notification settings - Fork 0
/
nginxDomainVirtualHost.php
172 lines (138 loc) · 6.73 KB
/
nginxDomainVirtualHost.php
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<?php
/**
* @var Template_VariableAccessor $VAR
* @var array $OPT
* To rebuild:
* /usr/local/psa/admin/bin/httpdmng --reconfigure-domain domain.com
*/
?>
<?php
/* Conf file path */
$conf_path = $VAR->domain->physicalHosting->customConfigFile;
$conf_path = str_replace('/vhost.conf','',$conf_path);
/* Custom hack for clean nginx redirect to ssl */
$redirect_to_ssl_file = $conf_path.'/redirect_to_ssl.php';
if (is_file($redirect_to_ssl_file)) include($redirect_to_ssl_file);
if ($redirect_to_ssl or $OPT['ssl'])
$OPT['redirect_scheme'] = 'https';
else $OPT['redirect_scheme'] = 'http';
?>
<?php
/* Custom hack for clean nginx Wordpress URL re-writing */
if (is_file($VAR->domain->physicalHosting->httpDir.'/wp-blog-header.php') or is_file($VAR->domain->physicalHosting->httpsDir.'/wp-blog-header.php')) $OPT['wordpress_site'] = true;
?>
<?php echo $VAR->includeTemplate('domain/service/nginxSeoSafeRedirects.php', array('ipAddress' => $OPT['ipAddress']->escapedAddress, 'ssl' => $OPT['ssl'], 'frontendPort' => $OPT['frontendPort'], 'redirect_scheme' => $OPT['redirect_scheme'])); ?>
server {
listen <?php echo $OPT['ipAddress']->escapedAddress . ':' . $OPT['frontendPort'] .
($OPT['default'] ? ' default_server' : '') . ($OPT['ssl'] ? ' ssl' : '') .
($OPT['ssl'] && $VAR->domain->physicalHosting->proxySettings['nginxHttp2'] ? ' http2' : '') ?>;
<?php if ($VAR->domain->isWildcard): ?>
server_name ~^<?php echo $VAR->domain->pcreName ?>$;
<?php else: ?>
<?php if ($VAR->domain->isSeoRedirectToLanding) : ?>
server_name <?php echo $VAR->domain->asciiName ?>;
<?php elseif ($VAR->domain->isSeoRedirectToWww): ?>
server_name www.<?php echo $VAR->domain->asciiName ?>;
<?php else: ?>
server_name <?php echo $VAR->domain->asciiName ?>;
server_name www.<?php echo $VAR->domain->asciiName ?>;
<?php endif; ?>
<?php if ($OPT['ipAddress']->isIpV6()): ?>
server_name ipv6.<?php echo $VAR->domain->asciiName ?>;
<?php else: ?>
server_name ipv4.<?php echo $VAR->domain->asciiName ?>;
<?php endif ?>
<?php endif ?>
<?php if ($VAR->domain->previewDomainName): ?>
server_name "<?php echo $VAR->domain->previewDomainName ?>";
<?php endif ?>
<?php if ($redirect_to_ssl && !$OPT['ssl']): ?>
return 301 https://<?php echo $VAR->domain->targetName ?>$request_uri;
<?php else: ?>
<?php if ($OPT['ssl']): ?>
<?php $sslCertificate = $VAR->server->sni && $VAR->domain->physicalHosting->sslCertificate ?
$VAR->domain->physicalHosting->sslCertificate :
$OPT['ipAddress']->sslCertificate; ?>
<?php if ($sslCertificate->ce): ?>
ssl_certificate <?php echo $sslCertificate->ceFilePath ?>;
ssl_certificate_key <?php echo $sslCertificate->ceFilePath ?>;
<?php if ($sslCertificate->ca): ?>
ssl_client_certificate <?php echo $sslCertificate->caFilePath ?>;
<?php endif ?>
<?php endif ?>
<?php endif ?>
<?php if (!empty($VAR->domain->physicalHosting->proxySettings['nginxClientMaxBodySize'])): ?>
client_max_body_size <?php echo $VAR->domain->physicalHosting->proxySettings['nginxClientMaxBodySize'] ?>;
<?php endif; ?>
<?php if ($VAR->domain->physicalHosting->scriptTimeout): ?>
proxy_read_timeout <?php echo min($VAR->domain->physicalHosting->scriptTimeout, 2147483); ?>;
<?php endif; ?>
root "<?php echo $OPT['ssl'] ? $VAR->domain->physicalHosting->httpsDir : $VAR->domain->physicalHosting->httpDir ?>";
access_log "<?php echo $VAR->domain->physicalHosting->logsDir . '/' . ($OPT['ssl'] ? 'proxy_access_ssl_log' : 'proxy_access_log') ?>";
error_log "<?php echo $VAR->domain->physicalHosting->logsDir . '/proxy_error_log' ?>";
<?php if ($OPT['default']): ?>
<?php echo $VAR->includeTemplate('service/nginxSitePreview.php') ?>
<?php endif; ?>
<?php echo $VAR->domain->physicalHosting->proxySettings['allowDeny'] ?>
location / {
<?php if ($OPT['wordpress_site']): ?>
index index.php index.cgi index.pl index.html index.xhtml index.htm index.shtml;
try_files $uri $uri/ /index.php?$args;
<?php else: ?>
<?php echo $VAR->includeTemplate('domain/service/proxy.php', $OPT); ?>
<?php endif; ?>
}
<?php if (!$VAR->domain->physicalHosting->proxySettings['nginxTransparentMode'] && !$VAR->domain->physicalHosting->proxySettings['nginxServeStatic']): ?>
location /internal-nginx-static-location/ {
alias <?php echo $OPT['documentRoot'] ?>/;
add_header X-Powered-By PleskLin;
internal;
}
<?php endif ?>
<?php if ($VAR->domain->active && !$VAR->domain->physicalHosting->proxySettings['nginxTransparentMode']): ?>
<?php if ($VAR->domain->physicalHosting->php && $VAR->domain->physicalHosting->proxySettings['nginxServePhp']
|| $VAR->domain->physicalHosting->proxySettings['nginxServeStatic']): ?>
<?php if ($VAR->domain->physicalHosting->proxySettings['fileSharingPrefix']): ?>
location ~ ^/<?php echo $VAR->domain->physicalHosting->proxySettings['fileSharingPrefix'] ?>/ {
<?php echo $VAR->includeTemplate('domain/service/proxy.php', $OPT); ?>
}
<?php endif; ?>
<?php endif; ?>
location @apache_proxy {
<?php echo $VAR->includeTemplate('domain/service/proxy.php', $OPT); ?>
}
<?php if ($VAR->domain->physicalHosting->proxySettings['nginxServeStatic']): ?>
<?php echo $VAR->includeTemplate('domain/service/nginxProtectedDirectories.php', $OPT); ?>
location ~ ^/(.*\.(<?php echo $VAR->domain->physicalHosting->proxySettings['nginxStaticExtensions'] ?>))$ {
try_files $uri @apache_proxy;
}
<?php endif ?>
<?php if ($VAR->domain->physicalHosting->php && $VAR->domain->physicalHosting->proxySettings['nginxServePhp']): ?>
<?php if ($VAR->domain->physicalHosting->hasWebstat): ?>
location ~ ^/(plesk-stat|webstat|webstat-ssl|ftpstat|anon_ftpstat|awstats-icon) {
<?php echo $VAR->includeTemplate('domain/service/proxy.php', $OPT); ?>
}
<?php endif; ?>
location ~ ^/~(.+?)(/.*?\.php)(/.*)?$ {
alias <?php echo $VAR->domain->physicalHosting->webUsersDir ?>/$1/$2;
<?php echo $VAR->includeTemplate('domain/service/fpm.php'); ?>
}
location ~ ^/~(.+?)(/.*)?$ {
<?php echo $VAR->includeTemplate('domain/service/proxy.php', $OPT); ?>
}
<?php echo $VAR->includeTemplate('domain/service/nginxWordpress.php', $OPT); ?>
location ~ \.php(/.*)?$ {
<?php echo $VAR->includeTemplate('domain/service/fpm.php'); ?>
}
<?php echo $VAR->includeTemplate('domain/service/nginxWordpressIndexing.php', $OPT); ?>
<?php endif ?>
location ~ /$ {
<?php echo $VAR->domain->physicalHosting->proxySettings['directoryIndex'] ?>
try_files $uri $uri/ /index.php?$args;
}
<?php endif ?>
<?php if (is_file($VAR->domain->physicalHosting->customNginxConfigFile)): ?>
include "<?php echo $VAR->domain->physicalHosting->customNginxConfigFile ?>";
<?php endif; ?>
<?php endif; ?>
}