-
Notifications
You must be signed in to change notification settings - Fork 79
/
nginx_templates.py
334 lines (280 loc) · 10.1 KB
/
nginx_templates.py
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
import multiprocessing
TEMPLATE_CONFIG_FILE = """
#AUTOMATICALLY GENERATED - DO NO EDIT!
user %(user)s %(user)s;
pid /var/run/nginx.pid;
worker_processes %(workers)s;
worker_rlimit_nofile 100000;
include /etc/nginx.modules.d/*.conf;
events {
worker_connections 4096;
include /etc/nginx.custom.events.d/*.conf;
}
http {
default_type application/octet-stream;
access_log off;
error_log %(log_root)s/error.log crit;
sendfile on;
tcp_nopush on;
keepalive_timeout 20;
client_header_timeout 20;
client_body_timeout 20;
reset_timedout_connection on;
send_timeout 20;
types_hash_max_size 2048;
gzip on;
gzip_disable "msie6";
gzip_proxied any;
gzip_min_length 256;
gzip_comp_level 4;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript text/x-js;
server_names_hash_bucket_size 128;
include mime.conf;
charset UTF-8;
open_file_cache max=100000 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 2;
open_file_cache_errors on;
server_tokens off;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
include proxy.conf;
include fcgi.conf;
include conf.d/*.conf;
include /etc/nginx.custom.d/*.conf;
}
include /etc/nginx.custom.global.d/*.conf;
""" % {
'workers': multiprocessing.cpu_count(),
'log_root': '/var/log/nginx',
'user': 'www-data',
}
TEMPLATE_CONFIG_PROXY = """
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffers 32 4k;
"""
TEMPLATE_CONFIG_FCGI = """
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $host;
fastcgi_param HTTPS $https;
fastcgi_param REDIRECT_STATUS 200;
"""
TEMPLATE_CONFIG_MIME = """
types {
text/html html htm shtml;
text/css css;
text/xml xml rss;
image/gif gif;
image/jpeg jpeg jpg;
application/x-javascript js;
text/plain txt;
text/x-component htc;
text/mathml mml;
image/png png;
image/svg+xml svg svgz;
image/x-icon ico;
image/x-jng jng;
image/vnd.wap.wbmp wbmp;
application/json json;
application/java-archive jar war ear;
application/mac-binhex40 hqx;
application/pdf pdf;
application/x-cocoa cco;
application/x-java-archive-diff jardiff;
application/x-java-jnlp-file jnlp;
application/x-makeself run;
application/x-perl pl pm;
application/x-pilot prc pdb;
application/x-rar-compressed rar;
application/x-redhat-package-manager rpm;
application/x-sea sea;
application/x-shockwave-flash swf;
application/x-stuffit sit;
application/x-tcl tcl tk;
application/x-x509-ca-cert der pem crt;
application/x-xpinstall xpi;
application/zip zip;
application/octet-stream deb;
application/octet-stream bin exe dll;
application/octet-stream dmg;
application/octet-stream eot;
application/octet-stream iso img;
application/octet-stream msi msp msm;
audio/mpeg mp3;
audio/ogg oga ogg;
audio/wav wav;
audio/x-realaudio ra;
video/mp4 mp4;
video/mpeg mpeg mpg;
video/ogg ogv;
video/quicktime mov;
video/webm webm;
video/x-flv flv;
video/x-msvideo avi;
video/x-ms-wmv wmv;
video/x-ms-asf asx asf;
video/x-mng mng;
}
"""
TEMPLATE_WEBSITE = """
#AUTOMATICALLY GENERATED - DO NO EDIT!
%(custom_conf_toplevel)s
server {
%(ports)s
%(ssl_cert)s
%(ssl_key)s
%(ssl_protocols)s
%(ssl_prefer_server_ciphers)s
%(ssl_dhparam)s
%(ssl_ciphers)s
%(ssl_session_timeout)s
%(ssl_session_cache)s
%(ssl_stapling)s
%(ssl_stapling_verify)s
%(ssl_header)s
%(server_name)s
access_log /var/log/nginx/%(slug)s.access.log;
error_log /var/log/nginx/%(slug)s.error.log;
root %(root)s;
index index.html index.htm index.php;
%(custom_conf)s
%(maintenance)s
%(locations)s
}
"""
TEMPLATE_MAINTENANCE = """
location / {
return 503;
error_page 503 @maintenance;
}
location @maintenance {
root /var/lib/ajenti/plugins/vh/extras;
rewrite ^(.*)$ /maintenance.html break;
}
"""
TEMPLATE_LOCATION = """
location %(match)s %(pattern)s {
%(path)s
%(custom_conf)s
%(content)s
}
"""
TEMPLATE_LOCATION_CONTENT_STATIC = """
%(autoindex)s
"""
TEMPLATE_LOCATION_CONTENT_PROXY = """
proxy_pass %(url)s;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header HTTPS $https;
"""
TEMPLATE_LOCATION_CONTENT_FCGI = """
include fcgi.conf;
fastcgi_pass %(url)s;
"""
TEMPLATE_LOCATION_CONTENT_PHP_FCGI = """
fastcgi_index index.php;
include fcgi.conf;
fastcgi_pass %(listen)s;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
"""
TEMPLATE_LOCATION_CONTENT_PHP56_FCGI = """
fastcgi_index index.php;
include fcgi.conf;
fastcgi_pass %(listen)s;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
"""
TEMPLATE_LOCATION_CONTENT_PHP70_FCGI = """
fastcgi_index index.php;
include fcgi.conf;
fastcgi_pass %(listen)s;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
"""
TEMPLATE_LOCATION_CONTENT_PHP71_FCGI = """
fastcgi_index index.php;
include fcgi.conf;
fastcgi_pass %(listen)s;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
"""
TEMPLATE_LOCATION_CONTENT_PHP72_FCGI = """
fastcgi_index index.php;
include fcgi.conf;
fastcgi_pass %(listen)s;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
"""
TEMPLATE_LOCATION_CONTENT_PHP73_FCGI = """
fastcgi_index index.php;
include fcgi.conf;
fastcgi_pass %(listen)s;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
"""
TEMPLATE_LOCATION_CONTENT_PHP74_FCGI = """
fastcgi_index index.php;
include fcgi.conf;
fastcgi_pass %(listen)s;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
"""
TEMPLATE_LOCATION_CONTENT_PHP80_FCGI = """
fastcgi_index index.php;
include fcgi.conf;
fastcgi_pass %(listen)s;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
"""
TEMPLATE_LOCATION_CONTENT_PHP81_FCGI = """
fastcgi_index index.php;
include fcgi.conf;
fastcgi_pass %(listen)s;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
"""
TEMPLATE_LOCATION_CONTENT_PYTHON_WSGI = """
proxy_pass http://unix:/var/run/ajenti-v-gunicorn-%(id)s.sock;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
"""
TEMPLATE_LOCATION_CONTENT_RUBY_UNICORN = """
proxy_pass http://unix:/var/run/ajenti-v-unicorn-%(id)s.sock;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
"""
TEMPLATE_LOCATION_CONTENT_RUBY_PUMA = """
proxy_pass http://unix:/var/run/ajenti-v-puma-%(id)s.sock;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
"""
TEMPLATE_LOCATION_CONTENT_NODEJS = """
proxy_pass http://127.0.0.1:%(port)i;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
"""