chui_zhi_api.conf.example 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. # 此文件应放在 Nginx http {} 上下文中,例如 /etc/nginx/conf.d/chui_zhi_api.conf。
  2. # 部署前替换 YOUR_API_DOMAIN 和证书路径。
  3. limit_req_zone $binary_remote_addr zone=chui_zhi_api_rate:10m rate=100r/s;
  4. limit_conn_zone $binary_remote_addr zone=chui_zhi_api_conn:10m;
  5. upstream chui_zhi_api_backend {
  6. server 127.0.0.1:8888;
  7. keepalive 64;
  8. }
  9. server {
  10. listen 80;
  11. listen [::]:80;
  12. server_name YOUR_API_DOMAIN;
  13. return 301 https://$host$request_uri;
  14. }
  15. server {
  16. listen 443 ssl http2;
  17. listen [::]:443 ssl http2;
  18. server_name YOUR_API_DOMAIN;
  19. ssl_certificate /etc/letsencrypt/live/YOUR_API_DOMAIN/fullchain.pem;
  20. ssl_certificate_key /etc/letsencrypt/live/YOUR_API_DOMAIN/privkey.pem;
  21. ssl_protocols TLSv1.2 TLSv1.3;
  22. ssl_session_cache shared:SSL:10m;
  23. ssl_session_timeout 1d;
  24. client_max_body_size 1m;
  25. gzip on;
  26. gzip_min_length 1k;
  27. gzip_types application/json;
  28. limit_req zone=chui_zhi_api_rate burst=200 nodelay;
  29. limit_conn chui_zhi_api_conn 50;
  30. add_header X-Content-Type-Options nosniff always;
  31. add_header Referrer-Policy no-referrer always;
  32. # 如果新加坡服务器有固定出口 IP,建议取消下面两行注释并替换 IP。
  33. # allow 203.0.113.10;
  34. # deny all;
  35. location = /api/v1/crawler/videos/query {
  36. limit_except POST {
  37. deny all;
  38. }
  39. proxy_pass http://chui_zhi_api_backend;
  40. proxy_http_version 1.1;
  41. proxy_set_header Connection "";
  42. proxy_set_header Host $host;
  43. proxy_set_header X-Real-IP $remote_addr;
  44. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  45. proxy_set_header X-Forwarded-Proto $scheme;
  46. proxy_set_header X-Request-ID $http_x_request_id;
  47. proxy_connect_timeout 5s;
  48. proxy_send_timeout 30s;
  49. proxy_read_timeout 40s;
  50. proxy_buffering on;
  51. }
  52. # 运维探针只允许本机访问,不作为公网业务接口暴露。
  53. location ~ ^/(health|ready)$ {
  54. allow 127.0.0.1;
  55. allow ::1;
  56. deny all;
  57. proxy_pass http://chui_zhi_api_backend;
  58. proxy_set_header Host $host;
  59. }
  60. location / {
  61. return 404;
  62. }
  63. }