-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathnginx.conf
123 lines (103 loc) · 3.44 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
# /etc/nginx/nginx.conf
# su nginx -s /usr/sbin/nginx -- -g 'daemon off;'
# su nginx -s /usr/sbin/nginx
load_module /usr/lib/nginx/modules/ngx_http_js_module.so;
# load_module /usr/lib/nginx/modules/ngx_stream_js_module.so;
# the "user" directive makes sense only if the master process runs with super-user privileges
# user nginx;
worker_processes 1;
# daemon off;
error_log stderr crit;
pid /tmp/nginx.pid;
events {
worker_connections 1024;
}
http {
access_log off;
js_path /etc/nginx/njs/;
js_import router.js;
# ssl_certificate /etc/letsencrypt/live/addr.my.id/fullchain.pem;
# ssl_certificate_key /etc/letsencrypt/live/addr.my.id/privkey.pem;
default_type application/octet-stream;
proxy_intercept_errors on;
root /etc/nginx/www/;
error_page 502 =503 /502.html;
map $host $domain {
"~*^www\.(.+)" $1;
default $host;
}
map $http_x_forwarded_proto $request_scheme {
"~*^(.+)$" $1;
default $scheme;
}
map $http_connection $request_http_connection {
~*upgrade "Upgrade";
~*close "close";
default "";
}
map $upstream_http_cache_control $response_cache_control {
"" "public, max-age=120";
default $upstream_http_cache_control;
}
# enable microcache only on reasonable extensions. avoid .zip, .tar.gz, etc.
map $uri $zone {
"~*\/(?:[^\/\.]+)?$" microcache;
"~*\.(?:php|html|json|xml|[^\.]{5,})$" microcache;
default off;
}
keepalive_timeout 30s;
keepalive_requests 512;
proxy_connect_timeout 5s;
proxy_read_timeout 120s;
# required by proxy_limit_rate, proxy_cache, etc.
proxy_buffering on;
# limit download speed
proxy_limit_rate 1m;
# disable request body buffering
client_max_body_size 0;
proxy_request_buffering off;
# microcaching
proxy_cache_path /tmp/nginx levels=1:2 keys_zone=microcache:200m inactive=120s;
proxy_cache_key $request_method$scheme$http_host$request_uri;
# enforces caching when no Cache-Control is set by upstream
proxy_cache_valid 200 301 302 404 120s;
proxy_hide_header Cache-Control;
add_header Cache-Control $response_cache_control;
add_header X-Cache-Status $upstream_cache_status always;
# typical proxy headers
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $request_scheme;
proxy_set_header Upgrade-Insecure-Requests "";
# support WebSocket
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $request_http_connection;
# mitigate httpoxy vulnerability https://httpoxy.org/
proxy_set_header Proxy "";
proxy_redirect off;
proxy_pass_header Server;
server_tokens off;
server {
listen 80 backlog=100 reuseport;
# listen 443 ssl backlog=100 reuseport;
js_set $target_port router.getTargetPort;
location = /502.html {
internal;
return 503 "<p>No application is running on this port ($target_port)?</p>";
}
location ~ /\.(?!well-known).* {
deny all;
log_not_found off;
}
location / {
sendfile on;
tcp_nopush on;
try_files /$domain/index.html @proxy;
}
location @proxy {
proxy_pass http://127.0.0.1:$target_port;
proxy_cache $zone;
}
}
}