2 ################################################
3 ### Managed by someone's ansible provisioner ###
4 ################################################
5 # Part of: https://git.somenet.org/root/pub/somesible.git
6 # 2017-2026 by someone <someone@somenet.org>
9 {% if vhost_custom.vhost_custom_pre_server != "" %}
11 ###############################
12 ### vhost_custom_pre_server ###
13 ###############################
14 {{ vhost_custom.vhost_custom_pre_server }}
18 {% if vhost_cache_on %}
19 proxy_cache_path /tmp/nginx_cachep_{{vhost_name}} levels=1:2 keys_zone=cachep_{{vhost_name}}:16m max_size=1g inactive=1440m use_temp_path=off;
20 fastcgi_cache_path /tmp/nginx_cachef_{{vhost_name}} levels=1:2 keys_zone=cachef_{{vhost_name}}:16m max_size=1g inactive=1440m use_temp_path=off;
23 {% if vhost_https_on %}
28 server_name {{vhost_name}} {{vhost_aliases}} {{vhost_aliases_nocert}};
30 ssl_certificate /etc/ssl/letsencrypt/{{vhost_name}}/fullchain.pem;
31 ssl_certificate_key /etc/ssl/letsencrypt/{{vhost_name}}/privkey.pem;
32 ssl_certificate /etc/ssl/letsencrypt-rsa/{{vhost_name}}/fullchain.pem;
33 ssl_certificate_key /etc/ssl/letsencrypt-rsa/{{vhost_name}}/privkey.pem;
34 ssl_protocols TLSv1.2 TLSv1.3;
35 ssl_ciphers HIGH:!aNULL:!MD5:!SHA1:!SHA256:!SHA384;
36 ssl_prefer_server_ciphers on;
37 # ssl_dhparam /etc/nginx/dhparams.pem;
38 ssl_session_cache shared:SSL:10m;
40 ssl_stapling_verify on;
41 add_header Strict-Transport-Security "max-age=31536000" always;
43 access_log /var/log/nginx/{{vhost_name}}-access.log;
44 error_log /var/log/nginx/{{vhost_name}}-error.log;
46 client_max_body_size 16G;
47 fastcgi_buffers 64 4K;
48 # fix 414 Request-URI Too Large.
49 large_client_header_buffers 4 64k;
51 {% if vhost_gzip_on %}
58 gzip_http_version 1.1;
59 gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
65 {% if vhost_cache_on %}
67 proxy_cache cachep_{{vhost_name}};
68 proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504;
69 proxy_cache_background_update on;
70 proxy_cache_revalidate on;
71 # proxy_cache_key $scheme$proxy_host$request_uri;
72 # proxy_cache_valid 200 302 60m;
73 # proxy_cache_valid 301 90m;
74 # proxy_cache_valid any 10m;
76 fastcgi_cache cachef_{{vhost_name}};
77 fastcgi_cache_use_stale error timeout invalid_header updating http_500 http_503;
78 fastcgi_cache_background_update on;
79 fastcgi_cache_revalidate on;
80 fastcgi_cache_key $request_uri;
81 # fastcgi_cache_valid 200 302 60m;
82 # fastcgi_cache_valid 301 90m;
83 # fastcgi_cache_valid any 10m;
85 add_header X-Cache-Status $upstream_cache_status always;
92 location ^~ /.well-known/acme-challenge {
93 alias /var/www/html/dehydrated;
96 {%- if vhost_dotfile_protection %}
98 ### <dotfile protection>
99 location ~ /\.(?!well-known\/).* {
102 ### </dotfile protection>
105 ### dotfile protection DISABLED! (not vhost_dotfile_protection)
109 location = /robots.txt {
111 try_files /{{vhost_name}}/robots.txt /html/robots.txt =404;
115 location ^~ /awstats-icon {
116 alias /usr/share/awstats/icon/;
118 auth_pam_service_name "nginx-awstats";
121 location = /awstats.pl {
122 root /usr/lib/cgi-bin/;
124 auth_pam_service_name "nginx-awstats";
128 include fastcgi_params;
129 fastcgi_pass unix:/var/run/fcgiwrap.socket;
130 fastcgi_param SCRIPT_FILENAME /usr/lib/cgi-bin/awstats.pl;
133 ### <maintenance part1>
134 error_page 503 @maintenance;
135 location @maintenance {
136 default_type text/html;
138 try_files /maintenance.html.{{vhost_name}} /maintenance.html /maintenance.html.dis =404;
140 set $maintenance "0";
141 if (-f "/var/www/maintenance.html") {
142 set $maintenance "1";
144 if (-f "/var/www/maintenance.html.{{vhost_name}}") {
145 set $maintenance "1";
147 {% for ip in vhost_maintenance_ips %}
148 if ($remote_addr = "{{ip}}") {
149 set $maintenance "0";
152 ### </maintenance part1>
154 ###############################
155 ### real config starts here ###
156 ###############################
157 {%- if vhost_type|lower() in ["php", "static"] %}
159 root /var/www/{{vhost_name}};
161 try_files $uri $uri/index.html $uri/ =404;
164 {%- if vhost_type|lower() == "static" %}
166 # remove /index.html from path
167 location ~ ^(.*/)index.html$ {
168 rewrite ^(.*/)index.html$ $1 permanent;
171 # remote trailing slashes from path
172 location ~ ^/(.*)/$ {
173 rewrite ^/(.*)/$ /$1 permanent;
176 {%- elif vhost_type|lower() == "php" %}
180 location ~ \.php($|/.*) {
181 if (!-f $document_root$fastcgi_script_name) {
185 include fastcgi_params;
186 fastcgi_pass unix:/var/run/php/php-fpm.sock;
187 fastcgi_param SCRIPT_FILENAME $request_filename;
189 fastcgi_split_path_info ^(.+\.php)($|/.*);
190 fastcgi_param PATH_INFO $fastcgi_path_info;
194 {%- elif vhost_type|lower() == "proxypass" %}
196 root /var/www/{{vhost_name}};
198 try_files $uri @proxy;
201 proxy_pass {{vhost_proxypass_target}};
202 proxy_http_version 1.1;
203 proxy_set_header Upgrade $http_upgrade;
204 proxy_set_header Connection $connection_upgrade;
205 proxy_set_header Host $http_host;
206 proxy_set_header X-Real-IP $remote_addr;
207 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
208 proxy_set_header X-Forwarded-Proto $scheme;
209 proxy_set_header X-Frame-Options SAMEORIGIN;
210 proxy_set_header Accept-Encoding "";
213 {%- elif vhost_type|lower() == "redirect" %}
215 return {{vhost_redirect_code}} $scheme://{{vhost_redirect_target_without_protocol}}$request_uri;
218 {%- if vhost_custom.vhost_custom != "" %}
223 {{ vhost_custom.vhost_custom | indent(width=4) }}
227 #############################
228 ### real config ends here ###
229 #############################
230 ### <maintenance part2>
231 if ($maintenance = "1") {
234 ### </maintenance part2>
238 {% if vhost_http_on %}
242 server_name {{vhost_name}} {{vhost_aliases}} {{vhost_aliases_nocert}};
244 access_log /var/log/nginx/{{vhost_name}}-access.log;
245 error_log /var/log/nginx/{{vhost_name}}-error.log;
247 client_max_body_size 1025M;
248 fastcgi_buffers 64 4K;
249 # fix 414 Request-URI Too Large.
250 large_client_header_buffers 4 64k;
252 {% if vhost_cache_on %}
254 proxy_cache cachep_{{vhost_name}};
255 proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504;
256 proxy_cache_background_update on;
257 proxy_cache_revalidate on;
258 # proxy_cache_key $scheme$proxy_host$request_uri;
259 # proxy_cache_valid 200 302 60m;
260 # proxy_cache_valid 301 90m;
261 # proxy_cache_valid any 10m;
263 fastcgi_cache cachef_{{vhost_name}};
264 fastcgi_cache_use_stale error timeout invalid_header updating http_500 http_503;
265 fastcgi_cache_background_update on;
266 fastcgi_cache_revalidate on;
267 fastcgi_cache_key $request_uri;
268 # fastcgi_cache_valid 200 302 60m;
269 # fastcgi_cache_valid 301 90m;
270 # fastcgi_cache_valid any 10m;
272 add_header X-Cache-Status $upstream_cache_status always;
275 ### proxy_cache DISABLED!
279 location ^~ /.well-known/acme-challenge {
280 alias /var/www/html/dehydrated;
283 {%- if vhost_dotfile_protection %}
285 ### <dotfile protection>
286 location ~ /\.(?!well-known\/).* {
289 ### </dotfile protection>
292 ### dotfile protection DISABLED! (not vhost_dotfile_protection)
296 location = /robots.txt {
298 try_files /{{vhost_name}}/$uri /html/$uri =404;
302 location ^~ /awstats-icon {
303 alias /usr/share/awstats/icon/;
305 auth_pam_service_name "nginx-awstats";
308 location = /awstats.pl {
309 root /usr/lib/cgi-bin/;
311 auth_pam_service_name "nginx-awstats";
315 include fastcgi_params;
316 fastcgi_pass unix:/var/run/fcgiwrap.socket;
317 fastcgi_param SCRIPT_FILENAME /usr/lib/cgi-bin/awstats.pl;
320 ### <maintenance part1>
321 error_page 503 @maintenance;
322 location @maintenance {
323 default_type text/html;
325 try_files /maintenance.html.{{vhost_name}} /maintenance.html /maintenance.html.dis =404;
327 set $maintenance "0";
328 if (-f "/var/www/maintenance.html") {
329 set $maintenance "1";
331 if (-f "/var/www/maintenance.html.{{vhost_name}}") {
332 set $maintenance "1";
334 {% for ip in vhost_maintenance_ips %}
335 if ($remote_addr = "{{ip}}") {
336 set $maintenance "0";
339 ### </maintenance part1>
341 ###############################
342 ### real config starts here ###
343 ###############################
344 {%- if vhost_type|lower() in ["php", "static"] %}
346 root /var/www/{{vhost_name}};
348 try_files $uri $uri/index.html $uri/ =404;
351 {%- if vhost_type|lower() == "static" %}
353 # remove /index.html from path
354 location ~ ^(.*/)index.html$ {
355 rewrite ^(.*/)index.html$ $1 permanent;
358 # remote trailing slashes from path
359 location ~ ^/(.*)/$ {
360 rewrite ^/(.*)/$ /$1 permanent;
363 {%- elif vhost_type|lower() == "php" %}
367 location ~ \.php($|/.*) {
368 if (!-f $document_root$fastcgi_script_name) {
372 include fastcgi_params;
373 fastcgi_pass unix:/var/run/php/php-fpm.sock;
374 fastcgi_param SCRIPT_FILENAME $request_filename;
376 fastcgi_split_path_info ^(.+\.php)($|/.*);
377 fastcgi_param PATH_INFO $fastcgi_path_info;
381 {%- elif vhost_type|lower() == "proxypass" %}
383 root /var/www/{{vhost_name}};
385 try_files $uri @proxy;
388 proxy_pass {{vhost_proxypass_target}};
389 proxy_http_version 1.1;
390 proxy_set_header Upgrade $http_upgrade;
391 proxy_set_header Connection $connection_upgrade;
392 proxy_set_header Host $http_host;
393 proxy_set_header X-Real-IP $remote_addr;
394 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
395 proxy_set_header X-Forwarded-Proto $scheme;
396 proxy_set_header X-Frame-Options SAMEORIGIN;
397 proxy_set_header Accept-Encoding "";
400 {%- elif vhost_type|lower() == "redirect" %}
402 return {{vhost_redirect_code}} $scheme://{{vhost_redirect_target_without_protocol}}$request_uri;
405 {%- if vhost_custom.vhost_custom != "" %}
410 {{ vhost_custom.vhost_custom | indent(width=4) }}
414 #############################
415 ### real config ends here ###
416 #############################
417 ### <maintenance part2>
418 if ($maintenance = "1") {
421 ### </maintenance part2>