Caddyfile.example 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. # Caddyfile example for Emergency Access Server
  2. # This configures Caddy to reverse proxy the emergency access server
  3. # running on localhost:1127
  4. # Example domain configuration
  5. emergency.example.com {
  6. # Enable TLS with automatic HTTPS
  7. tls your-email@example.com
  8. # Reverse proxy to the emergency access server
  9. reverse_proxy localhost:1127
  10. # Security headers
  11. header {
  12. # Hide server information
  13. -Server
  14. # Security headers
  15. X-Content-Type-Options nosniff
  16. X-Frame-Options DENY
  17. X-XSS-Protection "1; mode=block"
  18. Referrer-Policy strict-origin-when-cross-origin
  19. # Remove potentially sensitive headers
  20. -X-Powered-By
  21. }
  22. # Logging for security monitoring
  23. log {
  24. output file /var/log/caddy/emergency-access.log {
  25. roll_size 10mb
  26. roll_keep 30
  27. }
  28. format json
  29. level INFO
  30. }
  31. # Rate limiting to prevent abuse
  32. rate_limit {
  33. zone emergency {
  34. key {remote_host}
  35. events 10
  36. window 1m
  37. }
  38. }
  39. }
  40. # Alternative: Using a specific path instead of subdomain
  41. example.com {
  42. # Handle emergency access routes with specific path prefix
  43. handle /emergency/* {
  44. # Strip the /emergency prefix before forwarding
  45. uri strip_prefix /emergency
  46. # Forward to local server
  47. reverse_proxy localhost:1127
  48. # Additional security for emergency routes
  49. header {
  50. X-Content-Type-Options nosniff
  51. X-Frame-Options DENY
  52. Cache-Control "no-cache, no-store, must-revalidate"
  53. Pragma no-cache
  54. Expires 0
  55. }
  56. # More restrictive rate limiting for emergency routes
  57. rate_limit {
  58. zone emergency_strict {
  59. key {remote_host}
  60. events 5
  61. window 1m
  62. }
  63. }
  64. }
  65. # Handle other routes normally
  66. handle {
  67. # Your regular website content
  68. root * /var/www/html
  69. file_server
  70. }
  71. # Logging
  72. log {
  73. output file /var/log/caddy/main.log
  74. format json
  75. }
  76. }
  77. # IP-based access (for internal use)
  78. :443 {
  79. # Only allow specific IP addresses
  80. @allowed_ips remote_ip 10.0.0.0/8 172.16.0.0/12 192.168.0.0/16
  81. handle @allowed_ips {
  82. reverse_proxy localhost:1127
  83. header {
  84. X-Internal-Access "true"
  85. }
  86. }
  87. handle {
  88. respond "Access Denied" 403
  89. }
  90. tls internal
  91. }
  92. # Development/testing configuration (HTTP only)
  93. # Remove in production!
  94. localhost:8080 {
  95. reverse_proxy localhost:1127
  96. # Development headers
  97. header {
  98. X-Dev-Mode "true"
  99. }
  100. log {
  101. output stdout
  102. format console
  103. level DEBUG
  104. }
  105. }
  106. # Global options
  107. {
  108. # Email for Let's Encrypt
  109. email your-email@example.com
  110. # Enable experimental features if needed
  111. # experimental_http3
  112. # Security settings
  113. servers {
  114. protocols h1 h2 h2c
  115. }
  116. # Admin API (optional, restrict access in production)
  117. admin localhost:2019
  118. }