export disk read/write stats
[debiancodesearch.git] / nginx.example
blobeb5bda24cbd8e4f2eb39623f1f8896fc074cf5df
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;
35     listen   443 ssl;
36     listen   [::]:443 ssl ipv6only=on;
38     ssl_certificate /etc/ssl/certs/codesearch.debian.net.crt.pem;
39     ssl_certificate_key /etc/ssl/private/codesearch.debian.net.key;
41     # See http://cipherli.st/
42     ssl_ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AES:RSA+3DES:!ADH:!AECDH:!MD5:!DSS;
43     ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
44     ssl_prefer_server_ciphers on;
45     ssl_session_cache shared:SSL:10m;
46     #add_header Strict-Transport-Security "max-age=63072000; includeSubDomains";
47     # https://developer.mozilla.org/en-US/docs/Web/HTTP/X-Frame-Options
48     add_header X-Frame-Options DENY;
49     add_header X-Content-Type-Options nosniff;
50     ssl_stapling on; # Requires nginx >= 1.3.7
51     ssl_stapling_verify on; # Requires nginx => 1.3.7
52     resolver 8.8.8.8 8.8.4.4 valid=300s;
53     resolver_timeout 5s;
55     root /usr/share/dcs/static;
56     index index.html index.htm;
58     server_name codesearch.debian.net;
60     access_log /var/log/nginx/dcs-static.log combined;
62     # 5s is a reasonably high timeout for connections, but also still low
63     # enough that users might wait that long for a reply.
64     proxy_connect_timeout 5s;
66     # Use Keep-Alive to the upstream backend.
67     proxy_http_version 1.1;
68     proxy_set_header Connection "";
69     proxy_set_header Host $host;
70     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
72     gzip on;
73     gzip_comp_level 6;
74     gzip_types *;
75     gzip_proxied any;
77     location /nginx_status {
78         auth_basic off;
79         stub_status on;
80         access_log off;
81         allow 127.0.0.1;
82         deny all;
83     }
85     location = /instantws {
86         limit_req zone=one burst=3 nodelay;
88         proxy_set_header Upgrade $http_upgrade;
89         proxy_set_header Connection "upgrade";
90         proxy_set_header Host $host;
91         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
92         proxy_read_timeout 3600s;
93         proxy_send_timeout 3600s;
95         proxy_pass http://dcsweb;
96     }
98     location ~ ^/(perpackage-)?results/ {
99         limit_req zone=results burst=5 nodelay;
101         set $cache_key $scheme$host$uri$is_args$args$http_accept_encoding;
102         proxy_cache main;
103         proxy_cache_key $cache_key;
104         proxy_cache_valid 1h;
106         proxy_pass http://dcsweb;
107     }
109     # Server-rendered pages (cached and rate-limited) for legacy clients.
110     location ~ ^/(search|show) {
111         # Limit to 1 req/s on average.
112         limit_req zone=legacy burst=3 nodelay;
114         access_log /var/log/nginx/dcs-upstream.log upstream;
116         proxy_read_timeout 120s;
118         set $cache_key $scheme$host$uri$is_args$args$http_accept_encoding;
119         proxy_cache main;
120         proxy_cache_key $cache_key;
121         proxy_cache_valid 15m;
123         proxy_pass http://dcsweb;
124     }
126     # Everything else must be a static page, so we directly deliver (with
127     # appropriate caching headers).
128     location /research/ {
129         autoindex on;
130     }
132     location / {
133         # Cache static files for 24 hours.
134         expires 24h;
136         # First attempt to serve request as file, then
137         # as directory, then fall back to displaying a 404.
138         try_files $uri $uri.html $uri/ /index.html;
139     }
141     #error_page 404 /404.html;
143     # redirect server error pages to the static page /50x.html
144     error_page 500 502 503 504 /50x.html;