Caddyfile.juhe.pub 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. {
  2. servers {
  3. max_header_size 64KB
  4. timeouts {
  5. read_header 10s
  6. idle 2m
  7. }
  8. }
  9. }
  10. # Production domain
  11. juhe.pub {
  12. # This baseline assumes clients connect directly to Caddy. When Caddy is
  13. # behind a CDN, configure explicit trusted proxy CIDRs and {client_ip} as
  14. # documented in EDGE_SECURITY.md; {remote_host} would otherwise be the CDN.
  15. # =========================================================================
  16. # TLS 安全配置
  17. # =========================================================================
  18. tls {
  19. # 仅使用 TLS 1.2 和 1.3
  20. protocols tls1.2 tls1.3
  21. # 优先使用的加密套件
  22. ciphers TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
  23. }
  24. # =========================================================================
  25. # 反向代理配置
  26. # =========================================================================
  27. reverse_proxy 127.0.0.1:8080 {
  28. # 健康检查
  29. health_uri /health
  30. health_interval 30s
  31. health_timeout 10s
  32. health_status 200
  33. # 负载均衡策略(单节点可忽略,多节点时有用)
  34. lb_policy round_robin
  35. lb_try_duration 5s
  36. lb_try_interval 250ms
  37. # 仅从实际 TCP 对端生成转发头,避免透传客户端伪造值。
  38. header_up X-Real-IP {remote_host}
  39. header_up X-Forwarded-For {remote_host}
  40. header_up X-Forwarded-Proto {scheme}
  41. header_up X-Forwarded-Host {host}
  42. # 连接池优化
  43. transport http {
  44. keepalive 120s
  45. keepalive_idle_conns 256
  46. read_buffer 16KB
  47. write_buffer 16KB
  48. compression off
  49. }
  50. # 故障转移
  51. fail_duration 30s
  52. max_fails 3
  53. unhealthy_status 500 502 503 504
  54. }
  55. # =========================================================================
  56. # 压缩配置
  57. # =========================================================================
  58. encode {
  59. zstd
  60. gzip 6
  61. minimum_length 256
  62. match {
  63. # 不使用 text/*,否则 text/event-stream 会被压缩并缓冲到流结束
  64. header Content-Type text/css*
  65. header Content-Type text/csv*
  66. header Content-Type text/html*
  67. header Content-Type text/javascript*
  68. header Content-Type text/markdown*
  69. header Content-Type text/plain*
  70. header Content-Type text/xml*
  71. header Content-Type application/json*
  72. header Content-Type application/javascript*
  73. header Content-Type application/xml*
  74. header Content-Type application/rss+xml*
  75. header Content-Type image/svg+xml*
  76. }
  77. }
  78. # =========================================================================
  79. # 请求大小限制 (防止大文件攻击)
  80. # =========================================================================
  81. request_body {
  82. max_size 256MB
  83. }
  84. # =========================================================================
  85. # 日志配置
  86. # =========================================================================
  87. log {
  88. output file /var/log/caddy/sub2api.log {
  89. roll_size 50mb
  90. roll_keep 10
  91. roll_keep_for 720h
  92. }
  93. format json
  94. level INFO
  95. }
  96. # =========================================================================
  97. # 错误处理
  98. # =========================================================================
  99. handle_errors {
  100. respond "{err.status_code} {err.status_text}"
  101. }
  102. }