-
Notifications
You must be signed in to change notification settings - Fork 2
/
nginx.nix
147 lines (139 loc) · 4.49 KB
/
nginx.nix
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
# -*- coding: utf-8 -*-
# :Project: giskard -- nginx config
# :Created: dom 16 set 2018 22:17:55 CEST
# :Author: Alberto Berti <[email protected]>
# :License: GNU General Public License version 3 or later
# :Copyright: © 2018 Alberto Berti
#
{ config, pkgs, ... }:
let
logsBase = "/var/log/nginx";
in {
services = {
nginx = {
enable = true;
clientMaxBodySize = "10G";
recommendedOptimisation = true;
recommendedProxySettings = true;
appendHttpConfig = ''
map $host $this_host {
"" $host;
default $host;
}
map $http_x_forwarded_proto $the_scheme {
default $http_x_forwarded_proto;
"" $scheme;
}
map $http_x_forwarded_host $the_host {
default $http_x_forwarded_host;
"" $this_host;
}
'';
virtualHosts = {
"files.azazel.it" = {
enableACME = true;
forceSSL = true;
locations."/" = {
proxyPass = "http://files.azazel.it:18080";
};
extraConfig = ''
location ~* ^/ds-vpath/ {
rewrite /ds-vpath/(.*) /$1 break;
proxy_pass http://127.0.0.1:9980;
proxy_redirect off;
client_max_body_size 100m;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $the_host/ds-vpath;
proxy_set_header X-Forwarded-Proto $the_scheme;
}
proxy_max_temp_file_size 0;
location = /.well-known/carddav {
return 301 https://$host/remote.php/dav/;
}
location = /.well-known/caldav {
return 301 https://$host/remote.php/dav/;
}
error_log ${logsBase}/files.azazel.it-error.log;
access_log ${logsBase}/files.azazel.it-access.log combined;
'';
};
"azazel.it" = {
addSSL = true;
enableACME = true;
root = "/mnt/data/websites/azazel/.neuron/output";
extraConfig = ''
error_log ${logsBase}/azazel.it-error.log;
access_log ${logsBase}/azazel.it-access.log combined;
'';
};
"demo.azazel.it" = {
enableACME = true;
forceSSL = true;
serverAliases = [ "demo.metapensiero.it" ];
locations."/" = {
proxyPass = "http://localhost:8888";
};
};
"pentagramma.metapensiero.it" = {
enableACME = true;
forceSSL = true;
root = "/mnt/data/pentagramma";
extraConfig = ''
error_log ${logsBase}/pentagramma-error.log;
access_log ${logsBase}/pentagramma-access.log combined;
'';
};
"emiliacampagna.arstecnica.it" = {
enableACME = true;
forceSSL = true;
root = "/mnt/data/websites/emilia";
extraConfig = ''
error_log ${logsBase}/emiliacampagna-error.log;
access_log ${logsBase}/emiliacampagna-access.log combined;
'';
};
"viaggi.metapensiero.it" = {
enableACME = true;
forceSSL = true;
root = "/mnt/data/websites/viaggi";
extraConfig = ''
error_log ${logsBase}/viaggi-error.log;
access_log ${logsBase}/viaggi-access.log combined;
'';
};
};
};
logrotate = {
enable = true;
extraConfig = ''
weekly
rotate 8
/var/log/nginx/*.log {
weekly
missingok
rotate 60
compress
delaycompress
notifempty
create 0640 nginx nginx
sharedscripts
postrotate
kill -USR1 $(cat /run/nginx/nginx.pid)
endscript
}
'';
};
};
system.activationScripts.nginx_logging = {
text = ''
mkdir -p ${logsBase}
chown nginx:nginx -R ${logsBase}
'';
deps = [];
};
}