Moonglade

Modern Markdown blogging with AI-powered localization and search.

Tag: Caddy


Use Cloudflare with Caddy to Scrub Traffic

This article introduces a high-security reverse proxy configuration solution based on Caddy and Cloudflare. The core process uses a script to automatically fetch Cloudflare's latest IPv4 and IPv6 IP ranges and generate a `cloudflare_ips.conf` file containing the trusted proxy list and mandatory mutual TLS (mTLS) verification configuration. This configuration ensures that only Cloudflare nodes holding valid certificates can initiate requests, thereby supporting Full Strict mode. The build script `build_proxy.sh` is responsible for concatenating independent configuration files scattered across different business directories with the base baseline configuration to generate the final Caddyfile, achieving modularization and decoupling of business configurations for easier independent maintenance. During the deployment phase, the actual Cloudflare certificates are mounted into the container via Docker Volume, replacing the temporary certificates used during the build, enabling the service to perform actual work. Ultimately, this architecture implements a triple security mechanism: the use of Cloudflare certificates, strict mTLS client authentication, and trusting only Cloudflare as the front-end proxy. This design ensures extreme security while allowing backend services to transparently obtain the real client IP, balancing security and maintainability.

Views 203
ACME Caddy Cloudflare Docker MTLS Reverse Proxy

Visualize Caddy logs using Clickhouse

This article introduces how to leverage ClickHouse to build a Caddy log analysis system, enabling efficient data querying and visualization. The author first demonstrates that, after importing Caddy logs into ClickHouse, core metrics such as request volumes per business line, crawler IP identification, independent IP distribution, and CPU consumption can be rapidly aggregated through SQL statements. Additionally, the article details multiple practical query scenarios, including Top 100 popular endpoints, error code rankings, latency trend analysis based on P95/P99 percentiles, request size distribution, time-of-day traffic heatmaps, and User-Agent distribution, helping to gain deep insights into service performance and potential bottlenecks. In practice, the author successfully used this system to track and analyze a hacker's flood attack behavior, quickly locating the source of abnormal traffic through time-window filtering. Finally, the article demonstrates how to generate aesthetically pleasing visual reports using ClickHouse's built-in dashboards and the Grafana tool. The conclusion notes that setting up this infrastructure is of moderate difficulty; once established, it enables real-time monitoring of business metrics. For teams unfamiliar with application usage patterns, visualizing traffic data is an indispensable key method for evaluating business development.

Views 411
Caddy CaddyV2 Clickhouse Docker Python Superset