DEV Community

Arina Cholee
Arina Cholee

Posted on

Ditch Cloud WAFs: How to Migrate to Self-Hosted SafeLine WAF with Zero Downtime

Switching from a cloud WAF like Cloudflare to a self-hosted SafeLine WAF can seem intimidating. But if you want full control, better privacy, and fine-grained security rules, it’s a move worth considering.

In this guide, I’ll walk you through a practical migration process, highlight common pitfalls, and share actionable tips so you can migrate smoothly.

Why Migrate to SafeLine?

Cloud WAFs are convenient, but they come with limitations:

  • Data residency concerns: Traffic passes through third-party servers.
  • Limited rule customization: Templates exist, but granular control is restricted.
  • Latency & dependency: External proxies can introduce delays or single points of failure.

SafeLine WAF, being self-hosted, addresses these issues:

  • End-to-end traffic control
  • Granular bot protection & rate-limiting
  • Fully customizable rules per endpoint
  • Complete log visibility for auditing and analytics

Step 1: Audit Your Current WAF Setup

Before migration, document your existing configuration:

  • DNS setup: Note proxied subdomains and CNAMEs.
  • Rules & policies: Export IP blocklists, rate-limits, and bot protection settings.
  • SSL/TLS: Record certificates used.
  • Logging & analytics: Decide which logs you want to preserve or replicate.

Tip: Missing details here can cause headaches during cutover.

Step 2: Prepare SafeLine Environment

SafeLine runs on Linux, preferably with these specs:

  • CPU: 4+ cores
  • RAM: 8+ GB
  • Storage: SSD recommended for logs

Install SafeLine:

# Pull SafeLine Docker image
docker pull safeline/waf:latest

# Start SafeLine container
docker-compose up -d
Enter fullscreen mode Exit fullscreen mode

Check that your server is reachable and ports 80/443 are open.

Step 3: Configure SSL/TLS

If Cloudflare handled SSL at the edge, SafeLine supports:

  • Let’s Encrypt certificates
  • Custom certificates

⚡ Once configured, SafeLine can securely serve traffic without relying on Cloudflare’s proxy.

Step 4: Recreate Rules & Policies

Rebuild your WAF protections:

  • IP allow/block lists: Import existing lists
  • Rate limiting: Set per-endpoint limits
  • Bot protection: Enable JS/CAPTCHA challenges as needed
  • Custom rules: Regex-based request matching for fine-grained control

Example:

# Limit /api/login to 5 requests/sec per IP
docker exec -it safeline-cli set-rule /api/login rate-limit 5
Enter fullscreen mode Exit fullscreen mode

Step 5: DNS Cutover

  • Point your domain’s A/AAAA records to the SafeLine server.
  • Temporarily disable Cloudflare proxy (orange cloud → grey cloud) to test traffic.
  • Monitor SafeLine logs for errors or blocked requests.

💡 Pro tip: Use a staging subdomain first to validate rules before cutting over production traffic.

Step 6: Monitor & Fine-Tune

Once live:

# Monitor bot detection
tail -f /data/safeline/logs/nginx/safeline/access.log | grep "bot"
Enter fullscreen mode Exit fullscreen mode
  • Keep an eye on CPU and memory usage
  • Adjust custom rules based on real traffic patterns
  • Backup configurations regularly
  • Update SafeLine for security patches and new features

Key Considerations

  • Self-hosted responsibility: You manage server maintenance, backups, and uptime.
  • Granular control: Offers flexibility but requires careful tuning.
  • Parallel migration: Run Cloudflare and SafeLine in parallel during cutover to avoid downtime.

Developer Takeaways

  • Full control over traffic and WAF policies
  • Detailed logs for auditing and security insights
  • Endpoint-specific rules for smarter bot protection
  • Easy integration into CI/CD pipelines

Conclusion

Migrating from a cloud WAF to SafeLine may require planning, but the payoff is ownership, privacy, and flexibility. By following these steps, you can:

  • Safely migrate traffic
  • Maintain strong security protections
  • Fine-tune WAF behavior to match your application’s needs

SafeLine Resources

Top comments (0)