Bugfix: construct redirect URLs using net/url
[debiancodesearch.git] / nginx.example
blob0d2e4beaaed03d53d430c6c13e38a00134893e7c
1 # vim:ts=4:sw=4:expandtab
3 # Define a custom log format which includes the upstream latency time plus the
4 # contents of our own measurement data:
6 # 2001:4d88:100e:23:3a60:77ff:feab:d3ea - - [01/Oct/2012:23:03:41 +0200] "GET
7 # /search?q=XCreateWindow HTTP/1.1" 200 upstream 188.111.72.14:28080 response
8 # 0.756 request 0.756
10 log_format upstream '$remote_addr - - [$time_local] "$request" $status '
11     'upstream [$upstream_addr] [$upstream_response_time]=response request $request_time';
13 proxy_cache_path /var/cache/nginx/cache levels=1:2
14     keys_zone=main:50m
15     max_size=500m inactive=15m;
17 proxy_temp_path /var/cache/nginx/tmp;
19 upstream dcsweb {
20     # Keep at least 8 connections to the upstream server(s) open.
21     keepalive 8;
23     server localhost:28080;
26 # Set aside 10MB of RAM to store the req/s for each client IP address.
27 # This zone allows an average rate of 1 req/s.
28 limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s;
29 limit_req_zone $binary_remote_addr zone=legacy:10m rate=1r/s;
30 limit_req_zone $binary_remote_addr zone=results:10m rate=3r/s;
32 server {
33     listen   80;
34     listen   [::]:80 default_server ipv6only=on;
36     root /usr/share/dcs/static;
37     index index.html index.htm;
38     server_name codesearch.debian.net;
39     access_log /var/log/nginx/dcs-static.log combined;
41     location '/.well-known/acme-challenge' {
42         default_type "text/plain";
43         root /var/www/letsencrypt-webroot;
44     }
46     location / {
47         return 301 https://codesearch.debian.net$request_uri;
48     }
51 server {
52     listen   443 ssl http2;
53     listen   [::]:443 ssl http2 ipv6only=on;
55     ssl_certificate /etc/letsencrypt/live/codesearch.debian.net/fullchain.pem;
56     ssl_certificate_key /etc/letsencrypt/live/codesearch.debian.net/privkey.pem;
58     # See http://cipherli.st/
59     ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH";
60     ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
61     ssl_prefer_server_ciphers on;
62     ssl_session_cache shared:SSL:10m;
63     ssl_session_tickets off; # Requires nginx >= 1.5.9
64     add_header Strict-Transport-Security "max-age=31536000; includeSubdomains" always;
65     add_header X-Xss-Protection "1; mode=block" always;
66     add_header Content-Security-Policy "default-src: 'self'; script-src 'self' 'unsafe-inline' https://yandex.st" always;
67     # https://developer.mozilla.org/en-US/docs/Web/HTTP/X-Frame-Options
68     add_header X-Frame-Options DENY;
69     add_header X-Content-Type-Options nosniff;
70     ssl_stapling on; # Requires nginx >= 1.3.7
71     ssl_stapling_verify on; # Requires nginx => 1.3.7
72     resolver 8.8.8.8 8.8.4.4 valid=300s;
73     resolver_timeout 5s;
74     ssl_ecdh_curve secp384r1; # Requires nginx >= 1.1.0
75     ssl_dhparam /etc/nginx/dhparams.pem;
77     root /usr/share/dcs/static;
78     index index.html index.htm;
80     server_name codesearch.debian.net;
82     access_log /var/log/nginx/dcs-static.log combined;
84     # 5s is a reasonably high timeout for connections, but also still low
85     # enough that users might wait that long for a reply.
86     proxy_connect_timeout 5s;
88     # Use Keep-Alive to the upstream backend.
89     proxy_http_version 1.1;
90     proxy_set_header Connection "";
91     proxy_set_header Host $host;
92     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
94     gzip on;
95     gzip_comp_level 6;
96     gzip_proxied any;
97     # An up-to-date list can be found at:
98     # https://github.com/h5bp/server-configs-nginx/blob/master/nginx.conf
99     # Compress all output labeled with one of the following MIME-types.
100     gzip_types
101       application/atom+xml
102       application/javascript
103       application/json
104       application/ld+json
105       application/manifest+json
106       application/rss+xml
107       application/vnd.geo+json
108       application/vnd.ms-fontobject
109       application/x-font-ttf
110       application/x-web-app-manifest+json
111       application/xhtml+xml
112       application/xml
113       font/opentype
114       image/bmp
115       image/svg+xml
116       image/x-icon
117       text/cache-manifest
118       text/css
119       text/plain
120       text/vcard
121       text/vnd.rim.location.xloc
122       text/vtt
123       text/x-component
124       text/x-cross-domain-policy;
125     # text/html is always compressed by gzip module
127     location /nginx_status {
128         auth_basic off;
129         stub_status on;
130         access_log off;
131         allow 127.0.0.1;
132         deny all;
133     }
135     location = /instantws {
136         limit_req zone=one burst=3 nodelay;
138         proxy_set_header Upgrade $http_upgrade;
139         proxy_set_header Connection "upgrade";
140         proxy_set_header Host $host;
141         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
142         proxy_read_timeout 3600s;
143         proxy_send_timeout 3600s;
145         proxy_pass http://dcsweb;
146     }
148     location /events/ {
149         limit_req zone=one burst=3 nodelay;
151         proxy_set_header Host $host;
152         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
153         proxy_read_timeout 3600s;
154         proxy_send_timeout 3600s;
156         proxy_pass http://dcsweb;
157     }
159     location = /track {
160         limit_req zone=results burst=5 nodelay;
162         proxy_pass http://dcsweb;
163     }
165     location ~ ^/(perpackage-)?results/ {
166         limit_req zone=results burst=5 nodelay;
168         set $cache_key $scheme$host$uri$is_args$args$http_accept_encoding;
169         proxy_cache main;
170         proxy_cache_key $cache_key;
171         proxy_cache_valid 1h;
173         proxy_pass http://dcsweb;
174     }
176     # Server-rendered pages (cached and rate-limited) for legacy clients.
177     location ~ ^/(search|show) {
178         # Limit to 1 req/s on average.
179         limit_req zone=legacy burst=3 nodelay;
181         access_log /var/log/nginx/dcs-upstream.log upstream;
183         proxy_read_timeout 120s;
185         set $cache_key $scheme$host$uri$is_args$args$http_accept_encoding;
186         proxy_cache main;
187         proxy_cache_key $cache_key;
188         proxy_cache_valid 15m;
190         proxy_pass http://dcsweb;
191     }
193     location /placeholder.html {
194         proxy_pass http://dcsweb;
195     }
197     # Everything else must be a static page, so we directly deliver (with
198     # appropriate caching headers).
199     location /research/ {
200         autoindex on;
201     }
203     location / {
204         # Cache static files for half a year. We use cache busters (e.g. a ?2
205         # parameter) for every asset that needs updating.
206         expires 182d;
208         # First attempt to serve request as file, then
209         # as directory, then fall back to displaying a 404.
210         try_files $uri $uri.html $uri/ /index.html;
211     }
213     #error_page 404 /404.html;
215     # redirect server error pages to the static page /50x.html
216     error_page 500 502 503 504 /50x.html;