# 此文件应放在 Nginx http {} 上下文中,例如 /etc/nginx/conf.d/chui_zhi_api.conf。 # 部署前替换 YOUR_API_DOMAIN 和证书路径。 limit_req_zone $binary_remote_addr zone=chui_zhi_api_rate:10m rate=100r/s; limit_conn_zone $binary_remote_addr zone=chui_zhi_api_conn:10m; upstream chui_zhi_api_backend { server 127.0.0.1:8888; keepalive 64; } server { listen 80; listen [::]:80; server_name YOUR_API_DOMAIN; return 301 https://$host$request_uri; } server { listen 443 ssl http2; listen [::]:443 ssl http2; server_name YOUR_API_DOMAIN; ssl_certificate /etc/letsencrypt/live/YOUR_API_DOMAIN/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/YOUR_API_DOMAIN/privkey.pem; ssl_protocols TLSv1.2 TLSv1.3; ssl_session_cache shared:SSL:10m; ssl_session_timeout 1d; client_max_body_size 1m; gzip on; gzip_min_length 1k; gzip_types application/json; limit_req zone=chui_zhi_api_rate burst=200 nodelay; limit_conn chui_zhi_api_conn 50; add_header X-Content-Type-Options nosniff always; add_header Referrer-Policy no-referrer always; # 如果新加坡服务器有固定出口 IP,建议取消下面两行注释并替换 IP。 # allow 203.0.113.10; # deny all; location = /api/v1/crawler/videos/query { limit_except POST { deny all; } proxy_pass http://chui_zhi_api_backend; proxy_http_version 1.1; proxy_set_header Connection ""; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Request-ID $http_x_request_id; proxy_connect_timeout 5s; proxy_send_timeout 30s; proxy_read_timeout 40s; proxy_buffering on; } # 运维探针只允许本机访问,不作为公网业务接口暴露。 location ~ ^/(health|ready)$ { allow 127.0.0.1; allow ::1; deny all; proxy_pass http://chui_zhi_api_backend; proxy_set_header Host $host; } location / { return 404; } }