Caddyfile 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. # Caddyfile for client2server
  2. # Supports multiple server instances via Docker Compose
  3. {
  4. # Global options
  5. email your@email.com
  6. admin off
  7. auto_https off
  8. }
  9. # ========================================
  10. # WebSocket Load Balancer (port 3843)
  11. # ========================================
  12. ws://:3843 {
  13. # Backend servers (Docker network DNS)
  14. to server1:3843 server2:3843
  15. # Load balancing
  16. lb_try_duration 2s
  17. lb_try_interval 500ms
  18. # Keep WebSocket connections alive
  19. websocket
  20. # Health check
  21. health_check /health {
  22. interval 10s
  23. timeout 5s
  24. fails 2
  25. passes 1
  26. }
  27. # Preserve client info
  28. header_up X-Real-IP {remote}
  29. header_up X-Forwarded-For {remote}
  30. header_up X-Forwarded-Proto {scheme}
  31. header_up X-Client-ID {client_ip}
  32. # Timeouts for long-lived connections
  33. timeouts {
  34. read 300s
  35. write 300s
  36. idle 300s
  37. }
  38. }
  39. # ========================================
  40. # HTTP API (port 3844)
  41. # ========================================
  42. :3844 {
  43. # Health endpoint for each server
  44. handle /health* {
  45. respond "OK" 200
  46. }
  47. # Events webhook (HTTP fallback)
  48. handle /api/events* {
  49. reverse_proxy server1:3843
  50. }
  51. # Router management
  52. handle /api/routers* {
  53. reverse_proxy server1:3843
  54. }
  55. # Command endpoint
  56. handle /api/command* {
  57. reverse_proxy server1:3843
  58. }
  59. # Default
  60. respond "client2server API" 200
  61. }
  62. # ========================================
  63. # Dashboard (port 80/443)
  64. # ========================================
  65. :80, :443 {
  66. # Redirect to HTTPS
  67. respond / https://{$host}/dashboard {302}
  68. }
  69. # Dashboard placeholder (enable if you have a web UI)
  70. # localhost/dashboard {
  71. # reverse_proxy dashboard:3000
  72. # }
  73. # ========================================
  74. # TLS for HTTPS (optional)
  75. # ========================================
  76. # tls {
  77. # # Let's Encrypt (automatic)
  78. # }