fix feeder resource leak: close HTTP response body
[debiancodesearch.git] / nginx.example
blob5d221a968d6293758ab57e6a6c22e529f86fa6b9
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;
35     root /usr/share/dcs/static;
36     index index.html index.htm;
38     server_name codesearch.debian.net;
40     access_log /var/log/nginx/dcs-static.log combined;
42     # 5s is a reasonably high timeout for connections, but also still low
43     # enough that users might wait that long for a reply.
44     proxy_connect_timeout 5s;
46     # Use Keep-Alive to the upstream backend.
47     proxy_http_version 1.1;
48     proxy_set_header Connection "";
49     proxy_set_header Host $host;
51     gzip on;
52     gzip_comp_level 6;
53     gzip_types *;
55     location /nginx_status {
56         auth_basic off;
57         stub_status on;
58         access_log off;
59         allow 127.0.0.1;
60         deny all;
61     }
63     location = /instantws {
64         limit_req zone=one burst=3 nodelay;
66         proxy_set_header Upgrade $http_upgrade;
67         proxy_set_header Connection "upgrade";
68         proxy_read_timeout 3600s;
69         proxy_send_timeout 3600s;
71         proxy_pass http://dcsweb;
72     }
74     # We serve these perfectly cacheable JSON result files directly via nginx.
75     location ~ ^/results/(.*)/(.*\.json)$ {
76         alias /dcs-ssd/query_results/$1/$2;
77         autoindex on;
78         expires 1h;
79     }
81     location ~ ^/(perpackage-)?results/ {
82         limit_req zone=one burst=3 nodelay;
83         proxy_pass http://dcsweb;
84     }
86     # Server-rendered pages (cached and rate-limited) for legacy clients.
87     location ~ ^/(search|show) {
88         # Limit to 1 req/s on average.
89         limit_req zone=legacy burst=3 nodelay;
91         access_log /var/log/nginx/dcs-upstream.log upstream;
93         proxy_read_timeout 120s;
95         set $cache_key $scheme$host$uri$is_args$args$http_accept_encoding;
96         proxy_cache main;
97         proxy_cache_key $cache_key;
98         proxy_cache_valid 15m;
100         proxy_pass http://dcsweb;
101     }
103     # Everything else must be a static page, so we directly deliver (with
104     # appropriate caching headers).
105     location /research/ {
106         autoindex on;
107     }
109     location / {
110         # Cache static files for 24 hours.
111         expires 24h;
113         # First attempt to serve request as file, then
114         # as directory, then fall back to displaying a 404.
115         try_files $uri $uri.html $uri/ /index.html;
116     }
118     #error_page 404 /404.html;
120     # redirect server error pages to the static page /50x.html
121     error_page 500 502 503 504 /50x.html;