-
Notifications
You must be signed in to change notification settings - Fork 39
/
nginx.example
217 lines (175 loc) · 6.48 KB
/
nginx.example
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
# vim:ts=4:sw=4:expandtab
# Define a custom log format which includes the upstream latency time plus the
# contents of our own measurement data:
#
# 2001:4d88:100e:23:3a60:77ff:feab:d3ea - - [01/Oct/2012:23:03:41 +0200] "GET
# /search?q=XCreateWindow HTTP/1.1" 200 upstream 188.111.72.14:28080 response
# 0.756 request 0.756
#
log_format upstream '$remote_addr - - [$time_local] "$request" $status '
'upstream [$upstream_addr] [$upstream_response_time]=response request $request_time';
proxy_cache_path /var/cache/nginx/cache levels=1:2
keys_zone=main:50m
max_size=500m inactive=15m;
proxy_temp_path /var/cache/nginx/tmp;
upstream dcsweb {
# Keep at least 8 connections to the upstream server(s) open.
keepalive 8;
server localhost:28080;
}
# Set aside 10MB of RAM to store the req/s for each client IP address.
# This zone allows an average rate of 1 req/s.
limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s;
limit_req_zone $binary_remote_addr zone=legacy:10m rate=1r/s;
limit_req_zone $binary_remote_addr zone=results:10m rate=3r/s;
server {
listen 80;
listen [::]:80 default_server ipv6only=on;
root /usr/share/dcs/static;
index index.html index.htm;
server_name codesearch.debian.net;
access_log /var/log/nginx/dcs-static.log combined;
location '/.well-known/acme-challenge' {
default_type "text/plain";
root /var/www/letsencrypt-webroot;
}
location / {
return 301 https://codesearch.debian.net$request_uri;
}
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2 ipv6only=on;
ssl_certificate /etc/letsencrypt/live/codesearch.debian.net/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/codesearch.debian.net/privkey.pem;
# See http://cipherli.st/
ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH";
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_tickets off; # Requires nginx >= 1.5.9
add_header Strict-Transport-Security "max-age=31536000; includeSubdomains" always;
add_header X-Xss-Protection "1; mode=block" always;
add_header Content-Security-Policy "default-src: 'self'; script-src 'self' 'unsafe-inline' https://yandex.st" always;
# https://developer.mozilla.org/en-US/docs/Web/HTTP/X-Frame-Options
add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;
ssl_stapling on; # Requires nginx >= 1.3.7
ssl_stapling_verify on; # Requires nginx => 1.3.7
resolver 8.8.8.8 8.8.4.4 valid=300s;
resolver_timeout 5s;
ssl_ecdh_curve secp384r1; # Requires nginx >= 1.1.0
ssl_dhparam /etc/nginx/dhparams.pem;
root /usr/share/dcs/static;
index index.html index.htm;
server_name codesearch.debian.net;
access_log /var/log/nginx/dcs-static.log combined;
# 5s is a reasonably high timeout for connections, but also still low
# enough that users might wait that long for a reply.
proxy_connect_timeout 5s;
# Use Keep-Alive to the upstream backend.
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
gzip on;
gzip_comp_level 6;
gzip_proxied any;
# An up-to-date list can be found at:
# https://github.com/h5bp/server-configs-nginx/blob/master/nginx.conf
# Compress all output labeled with one of the following MIME-types.
gzip_types
application/atom+xml
application/javascript
application/json
application/ld+json
application/manifest+json
application/rss+xml
application/vnd.geo+json
application/vnd.ms-fontobject
application/x-font-ttf
application/x-web-app-manifest+json
application/xhtml+xml
application/xml
font/opentype
image/bmp
image/svg+xml
image/x-icon
text/cache-manifest
text/css
text/plain
text/vcard
text/vnd.rim.location.xloc
text/vtt
text/x-component
text/x-cross-domain-policy;
# text/html is always compressed by gzip module
location /nginx_status {
auth_basic off;
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}
location = /instantws {
limit_req zone=one burst=3 nodelay;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_read_timeout 3600s;
proxy_send_timeout 3600s;
proxy_pass http://dcsweb;
}
location /events/ {
limit_req zone=one burst=3 nodelay;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_read_timeout 3600s;
proxy_send_timeout 3600s;
proxy_pass http://dcsweb;
}
location = /track {
limit_req zone=results burst=5 nodelay;
proxy_pass http://dcsweb;
}
location ~ ^/(perpackage-)?results/ {
limit_req zone=results burst=5 nodelay;
set $cache_key $scheme$host$uri$is_args$args$http_accept_encoding;
proxy_cache main;
proxy_cache_key $cache_key;
proxy_cache_valid 1h;
proxy_pass http://dcsweb;
}
# Server-rendered pages (cached and rate-limited) for legacy clients.
location ~ ^/(search|show) {
# Limit to 1 req/s on average.
limit_req zone=legacy burst=3 nodelay;
access_log /var/log/nginx/dcs-upstream.log upstream;
proxy_read_timeout 120s;
set $cache_key $scheme$host$uri$is_args$args$http_accept_encoding;
proxy_cache main;
proxy_cache_key $cache_key;
proxy_cache_valid 15m;
proxy_pass http://dcsweb;
}
location /placeholder.html {
proxy_pass http://dcsweb;
}
# Everything else must be a static page, so we directly deliver (with
# appropriate caching headers).
location /research/ {
autoindex on;
}
location / {
# Cache static files for half a year. We use cache busters (e.g. a ?2
# parameter) for every asset that needs updating.
expires 182d;
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri.html $uri/ /index.html;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
}