generate result pages as necessary
[debiancodesearch.git] / nginx.example
blob6fed299ca0c800e6845423204adb9d0b14084eeb
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;
31 server {
32     listen   80;
33     listen   [::]:80 default_server ipv6only=on;
34     listen   443 ssl;
35     listen   [::]:443 ssl ipv6only=on;
37     ssl_certificate /etc/ssl/certs/codesearch.debian.net.crt.pem;
38     ssl_certificate_key /etc/ssl/private/codesearch.debian.net.key;
40     # See http://cipherli.st/
41     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;
42     ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
43     ssl_prefer_server_ciphers on;
44     ssl_session_cache shared:SSL:10m;
45     #add_header Strict-Transport-Security "max-age=63072000; includeSubDomains";
46     # https://developer.mozilla.org/en-US/docs/Web/HTTP/X-Frame-Options
47     add_header X-Frame-Options DENY;
48     add_header X-Content-Type-Options nosniff;
49     ssl_stapling on; # Requires nginx >= 1.3.7
50     ssl_stapling_verify on; # Requires nginx => 1.3.7
51     resolver 8.8.8.8 8.8.4.4 valid=300s;
52     resolver_timeout 5s;
54     root /usr/share/dcs/static;
55     index index.html index.htm;
57     server_name codesearch.debian.net;
59     access_log /var/log/nginx/dcs-static.log combined;
61     # 5s is a reasonably high timeout for connections, but also still low
62     # enough that users might wait that long for a reply.
63     proxy_connect_timeout 5s;
65     # Use Keep-Alive to the upstream backend.
66     proxy_http_version 1.1;
67     proxy_set_header Connection "";
68     proxy_set_header Host $host;
69     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
71     gzip on;
72     gzip_comp_level 6;
73     gzip_types *;
74     gzip_proxied any;
76     location /nginx_status {
77         auth_basic off;
78         stub_status on;
79         access_log off;
80         allow 127.0.0.1;
81         deny all;
82     }
84     location = /instantws {
85         limit_req zone=one burst=3 nodelay;
87         proxy_set_header Upgrade $http_upgrade;
88         proxy_set_header Connection "upgrade";
89         proxy_set_header Host $host;
90         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
91         proxy_read_timeout 3600s;
92         proxy_send_timeout 3600s;
94         proxy_pass http://dcsweb;
95     }
97     location ~ ^/(perpackage-)?results/ {
98         limit_req zone=one burst=3 nodelay;
100         set $cache_key $scheme$host$uri$is_args$args$http_accept_encoding;
101         proxy_cache main;
102         proxy_cache_key $cache_key;
103         proxy_cache_valid 1h;
105         proxy_pass http://dcsweb;
106     }
108     # Server-rendered pages (cached and rate-limited) for legacy clients.
109     location ~ ^/(search|show) {
110         # Limit to 1 req/s on average.
111         limit_req zone=legacy burst=3 nodelay;
113         access_log /var/log/nginx/dcs-upstream.log upstream;
115         proxy_read_timeout 120s;
117         set $cache_key $scheme$host$uri$is_args$args$http_accept_encoding;
118         proxy_cache main;
119         proxy_cache_key $cache_key;
120         proxy_cache_valid 15m;
122         proxy_pass http://dcsweb;
123     }
125     # Everything else must be a static page, so we directly deliver (with
126     # appropriate caching headers).
127     location /research/ {
128         autoindex on;
129     }
131     location / {
132         # Cache static files for 24 hours.
133         expires 24h;
135         # First attempt to serve request as file, then
136         # as directory, then fall back to displaying a 404.
137         try_files $uri $uri.html $uri/ /index.html;
138     }
140     #error_page 404 /404.html;
142     # redirect server error pages to the static page /50x.html
143     error_page 500 502 503 504 /50x.html;