forked from phuslu/readme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nginx.conf
254 lines (213 loc) · 7.75 KB
/
nginx.conf
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
server {
#listen 443 ssl http2 default_server;
#ssl on;
#ssl_certificate /home/phuslu/.acme.sh/phus.lu/fullchain.cer;
#ssl_certificate_key /home/phuslu/.acme.sh/phus.lu/phus.lu.key;
listen 80;
server_name phus.lu;
server_tokens off;
charset utf-8;
index index.html index.htm index.php default.html default.htm default.php;
root /home/phuslu/wwwroot;
#root /var/www/html;
client_max_body_size 64M;
add_header public-key-pins 'pin-sha256="YLh1dUR9y6Kja30RrAn7JKnbQG/uEtLMkBgFF2Fuihg="; pin-sha256="sRHdihwgkaib1P1gxX8HFszlD+7/gTfNvuAybgLPNis="; max-age=5184000; includeSubDomains';
add_header strict-transport-security "max-age=63072000; includeSubDomains; preload";
add_header expect-ct 'max-age=0; report-uri="https://phuslu.report-uri.io/r/default/ct/reportOnly"';
add_header cache-control "no-cache";
add_header referrer-policy "no-referrer";
add_header access-control-allow-origin "*";
add_header x-robots-tag "noindex, nofollow";
add_header x-content-type-options nosniff;
add_header x-xss-protection "1; mode=block";
add_header x-frame-options sameorigin;
gzip on;
gzip_proxied any;
gzip_types text/plain text/xml text/css application/x-javascript;
gzip_vary on;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
location ~ ^(.*)/$ {
#if ($http_x_forwarded_proto = "") { rewrite ^(.*)$ https://$host$1 permanent; }
autoindex on;
autoindex_localtime on;
autoindex_exact_size off;
add_after_body /autoindex.html;
}
location ~ \.(pac|lua|conf|service)$ {
default_type text/plain;
}
location ~ \.md$ {
default_type text/html;
add_after_body /markdown.html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location /cgi-bin/ {
gzip off;
#root /var/www/www.example.com;
fastcgi_split_path_info ^(.+\.cgi)(/.+)$;
fastcgi_pass unix:/var/run/fcgiwrap.socket;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ ^/(i|test)$ {
rewrite ^/(\w+)$ /notepad.php?f=$1 last;
}
location ~ /metrics {
#rewrite ^ /cgi-bin/node_exporter.cgi last;
proxy_pass http://127.0.0.1:9100;
proxy_http_version 1.1;
proxy_read_timeout 90;
proxy_set_header host $host;
proxy_set_header connection "";
proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for;
proxy_set_header x-forwarded-proto https;
proxy_set_header x-real-ip $remote_addr;
proxy_redirect off;
proxy_redirect http:// https://;
# upgrade connection for websocket
set $proxy_upgrade "";
set $proxy_connection "";
if ($http_upgrade != ''){
set $proxy_upgrade $http_upgrade;
set $proxy_connection "upgrade";
}
proxy_set_header upgrade $proxy_upgrade;
proxy_set_header connection $proxy_connection;
}
}
log_format logstash_json '{ "@timestamp": "$time_iso8601", '
'"@fields": { '
'"remote_addr": "$remote_addr", '
'"remote_user": "$remote_user", '
'"x_forwarded_for": "$http_x_forwarded_for", '
'"x_real_ip": "$http_x_real_ip", '
'"body_bytes_sent": "$body_bytes_sent", '
'"request_time": "$request_time", '
'"host": "$host", '
'"status": "$status", '
'"request": "$request", '
'"request_method": "$request_method", '
'"http_referrer": "$http_referer", '
'"http_user_agent": "$http_user_agent" } }';
upstream backend_api_servers {
zone upstream_dynamic 64k;
keepalive 64;
#ip_hash;
server 127.0.0.1:10001 max_fails=0 fail_timeout=3s;
server 127.0.0.1:10002 max_fails=0 fail_timeout=3s;
}
server {
listen 80;
server_name api.phus.lu;
access_log /var/log/nginx/api.phus.lu.log logstash_json;
gzip on;
gzip_proxied any;
gzip_types
text/css
text/javascript
text/xml
text/plain
application/javascript
application/x-javascript
application/json;
location / {
proxy_pass http://backend_api_servers;
proxy_next_upstream error timeout http_500 http_502 http_503 http_504;
proxy_http_version 1.1;
proxy_read_timeout 90;
proxy_redirect off;
proxy_set_header host $host;
proxy_set_header connection "";
proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for;
proxy_set_header x-forwarded-proto https;
proxy_set_header x-real-ip $remote_addr;
break;
}
}
proxy_cache_path /var/cache/nginx/cdn_phus_lu levels=1:2 keys_zone=cdn_phus_lu:100m inactive=1d max_size=1g;
server {
listen 80;
server_name cdn.phus.lu git.phus.lu;
gzip on;
gzip_proxied any;
gzip_types
text/css
text/javascript
text/xml
text/plain
application/javascript
application/x-javascript
application/json;
location / {
resolver 223.5.5.5 valid=300s ipv6=off;
set $backend "phuslu.github.io";
proxy_pass https://$backend;
proxy_http_version 1.1;
proxy_redirect off;
proxy_set_header host $backend;
proxy_set_header connection "";
proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for;
#proxy_set_header x-real-ip $remote_addr;
# see https://linux.cn/article-5945-1.html
proxy_cache cdn_phus_lu;
proxy_cache_key $host$uri$is_args$args;
proxy_cache_valid 200 2d;
proxy_cache_valid any 1d;
proxy_cache_min_uses 1;
proxy_cache_lock on;
proxy_cache_revalidate on;
proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504;
# make edge server happy
add_header cache-control "public, max-age=86400";
proxy_hide_header cache-control;
proxy_ignore_headers cache-control;
}
}
server {
listen 80;
server_name utserver.phus.lu;
location = / {
rewrite ^(.*)$ https://$host/gui/web/index.html permanent;
}
location / {
proxy_pass http://127.0.0.1:8080;
proxy_http_version 1.1;
proxy_read_timeout 90;
proxy_redirect off;
proxy_set_header host $host;
proxy_set_header connection "";
proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for;
proxy_set_header x-forwarded-proto https;
proxy_set_header x-real-ip $remote_addr;
}
}
map $host $backend {
grafana.phus.lu "127.0.0.1:3000";
shell.phus.lu "127.0.0.1:4200";
prometheus.phus.lu "127.0.0.1:9090";
gateway.phus.lu "192.168.2.1:80";
alpine.phus.lu "172.17.0.2:80";
}
server {
listen 80;
server_name *.phus.lu;
location / {
proxy_pass http://$backend;
proxy_http_version 1.1;
proxy_read_timeout 90;
proxy_redirect off;
proxy_set_header host $host;
proxy_set_header connection "";
proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for;
proxy_set_header x-forwarded-proto https;
proxy_set_header x-real-ip $remote_addr;
}
}