Files

71 lines
2.9 KiB
Nginx Configuration File

worker_processes auto;
pid /tmp/nginx.pid;
error_log /dev/stderr warn;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$request_method $uri $status $request_time '
'$upstream_response_time $request_id';
access_log /dev/stdout main;
sendfile on;
tcp_nopush on;
keepalive_timeout 30s;
server_tokens off;
# Default request body limit: the JSON API bodies of the contract are
# small. The 5 MB resume upload has no operation in the contract yet; the
# route that gets one raises the limit in its own location in app.conf.
# The edge proxy allows 10 MB (EDGE_MAX_BODY) and must stay at or above
# the largest limit here.
client_max_body_size 1m;
client_header_timeout 10s;
client_body_timeout 30s;
send_timeout 30s;
client_body_temp_path /tmp/client_body;
proxy_temp_path /tmp/proxy;
fastcgi_temp_path /tmp/fastcgi;
scgi_temp_path /tmp/scgi;
uwsgi_temp_path /tmp/uwsgi;
# Coarse per-client protection only. $remote_addr is the client address
# that app.conf resolved through the trusted edge (realip), never a value
# the client supplied. The values are far above normal browsing: the
# per-account and per-route quotas stay in the backend and are not
# replaced by these. The zones keep addresses in memory only; the access
# log does not record them.
#
# The key is the address, except that an IPv6 address counts as its /64
# network (as middleware.LimiterKey does in the backend): one subscriber
# controls a whole /64 and could otherwise take a new bucket per request.
# $remote_addr is canonical text here (inet_ntop from the edge), so the
# first four groups, or the part before "::", name the network. The two
# spellings of one /64 that differ in where "::" falls get two buckets, a
# harmless looseness for a coarse limit.
map $remote_addr $limit_key {
"~^(?<v6full>(?:[0-9a-f]{1,4}:){4})" $v6full;
"~^(?<v6short>(?:[0-9a-f]{1,4}(?::[0-9a-f]{1,4}){0,2})?::)" $v6short;
default $remote_addr;
}
limit_req_zone $limit_key zone=api_rate:10m rate=20r/s;
limit_conn_zone $limit_key zone=api_conn:10m;
limit_req_zone $limit_key zone=telemetry_rate:10m rate=30r/m;
limit_req_status 429;
limit_conn_status 429;
# A rejection line in the error log names the client address. Rejections
# are routine under a flood and the address must not be logged, so they
# are logged at notice, below the warn threshold of error_log above
# (the default, error, would write them with the address).
limit_req_log_level notice;
limit_conn_log_level notice;
resolver 127.0.0.11 valid=30s ipv6=off;
include /etc/nginx/conf.d/*.conf;
}