按使用场景分组,点击"复制"按钮一键复制命令
upstream backend { server 10.0.0.1:8080 weight=1; server 10.0.0.2:8080; }
upstream backend { server 10.0.0.1:8080 max_fails=3 fail_timeout=30s; }
upstream backend { keepalive 32; } proxy_http_version 1.1; proxy_set_header Connection "";
upstream backend { ip_hash; server 10.0.0.1:8080; }
proxy_connect_timeout 5s; proxy_send_timeout 60s; proxy_read_timeout 60s;
gzip on; gzip_min_length 1k; gzip_types text/css application/javascript application/json;
location ~* \.(js|css|png|jpg|svg)$ { expires 30d; add_header Cache-Control "public"; }
location = /index.html { add_header Cache-Control "no-cache, no-store"; }
proxy_cache_path /data/cache levels=1:2 keys_zone=api:10m max_size=1g inactive=60m;
proxy_cache api; proxy_cache_valid 200 10m; add_header X-Cache-Status $upstream_cache_status;
log_format main '$remote_addr [$time_local] "$request" $status rt=$request_time';
log_format timed '$request $status upstream=$upstream_addr urt=$upstream_response_time';
limit_req_zone $binary_remote_addr zone=api:10m rate=10r/s;
limit_req zone=api burst=20 nodelay;
limit_conn_zone $binary_remote_addr zone=perip:10m; limit_conn perip 10;