Docs cipi.yml Web panel API MCP Guides Compare GitHub Telegram channel
  1. Home
  2. Guides
  3. Cloudflare in front of Laravel, explained: DNS, proxy, SSL modes and wildcards
Operations

Cloudflare in front of Laravel, explained: DNS, proxy, SSL modes and wildcards

Put a Laravel app on Cipi behind Cloudflare without redirect loops or broken certificates: DNS records, orange vs grey cloud, every SSL/TLS mode explained, wildcard certificates over DNS, real visitor IPs, caching rules, WAF, WebSockets and upload limits, step by step.

By Updated 4 min read

Cloudflare sits between your visitors and your server. Used well, it adds a CDN, DDoS protection and a firewall for free. Used wrong, it causes the two classic problems: redirect loops and certificate errors. This guide sets it up correctly for an app on Cipi, and explains every setting so you know why.

Key ideas, in plain words#

TermMeaning
DNS only (grey cloud)Cloudflare only answers DNS; visitors connect to your server directly
Proxied (orange cloud)Visitors connect to Cloudflare; Cloudflare connects to your server
Edge certificateThe certificate visitors see, from Cloudflare (when proxied)
Origin certificateThe certificate on your server, for Cloudflare-to-server traffic
SSL/TLS modeHow Cloudflare talks to your server: not at all, HTTP, or HTTPS (checked or not)
DNS-01Proving domain ownership with a DNS record: needed for wildcard certificates
Step 1 of 4Visitor

The browser connects to Cloudflare (orange cloud) and gets Cloudflare's edge certificate.

Before you start#

  • A domain whose DNS is (or will be) on Cloudflare. Moving DNS to Cloudflare is free and doesn't move your website: you copy the records, then change the nameservers at your registrar.
  • An app on Cipi (first deploy).

1. DNS records#

In Cloudflare, DNS → Records:

TypeNameContentProxy status
A@your server IPv4Orange or grey
Awwwyour server IPv4Same as @
AAAA@, wwwyour server IPv6 (if any)Same
A*your server IPv4Only for wildcards

Start grey (DNS only) until the site works over HTTPS, then switch to orange. That way you test one thing at a time.

2. Choose the SSL/TLS mode: Full (strict)#

SSL/TLS → Overview. This is the setting that breaks most sites:

ModeCloudflare → your serverWith Cipi
OffNo HTTPS at allDon't
FlexibleHTTPRedirect loop: Cipi sends HTTP to HTTPS, forever
FullHTTPS, certificate not checkedWorks, but an attacker in between wouldn't be noticed
Full (strict)HTTPS, certificate checkedUse this

Full (strict) needs a valid certificate on your server. Cipi gives you one:

bash
sudo cipi ssl install shop                      # Let's Encrypt over HTTP
# or, if the record is already orange or you need wildcards:
sudo cipi ssl dns set --token=YOUR_CLOUDFLARE_TOKEN
sudo cipi ssl install shop --dns=cloudflare     # Let's Encrypt over DNS

DNS validation (--dns=cloudflare) works whatever the proxy status and even with port 80 closed. If you're behind Cloudflare, prefer it: renewals never depend on Cloudflare rules.

3. Create the API token (for DNS validation)#

My Profile → API Tokens → Create Token → Edit zone DNS template. Limit it to your zone. That's the only permission needed (Zone → DNS → Edit). Save it once on the server:

bash
sudo cipi ssl dns set --token=YOUR_CLOUDFLARE_TOKEN
sudo cipi ssl dns list

Several Cloudflare accounts (one per client)? Name them: --name=client-a, then --account=client-a when issuing (SSL docs).

4. Switch on the proxy#

When https://shop.example.com works with the grey cloud, click the cloud to make it orange, for @ and www. Then, in SSL/TLS → Edge Certificates:

SettingSet toWhy
Always Use HTTPSOnCloudflare redirects HTTP itself
Minimum TLS Version1.2Old clients only
Automatic HTTPS RewritesOnFixes mixed http:// links
HSTSOn, only after everything works over HTTPSBrowsers refuse HTTP for months: hard to undo

5. Wildcards: every subdomain, one certificate#

For multi-tenant apps (acme.example.com, globex.example.com…):

bash
sudo cipi alias add saas '*.example.com'        # quotes matter
sudo cipi ssl install saas --dns=cloudflare     # ~1 minute
curl -sI https://test.example.com | head -1
FactConsequence
Let's Encrypt issues wildcards only via DNS-01Cipi needs the Cloudflare token (step 3)
Cloudflare's free edge certificate covers example.com and *.example.comKeep tenants one level deep
Exact names beat the wildcardapi.example.com can still be another app

Full walkthrough with Laravel tenant resolution: Multi-tenant SaaS on wildcard subdomains.

6. Real visitor IPs#

Behind the orange cloud, every request comes from a Cloudflare IP. Two layers must know that:

  1. Nginx must take the visitor's IP from Cloudflare's header. sudo cipi zt enable configures exactly that (Cloudflare's ranges, refreshed daily) and teaches Fail2ban and CrowdSec the same ranges. It closes no port: it's the first step of Zero Trust, safe to run alone.
  2. Laravel must trust the proxy, so $request->ip(), rate limiting and HTTPS detection work. In bootstrap/app.php:
php
->withMiddleware(function (Middleware $middleware): void {
    $middleware->trustProxies(at: '*');
})

Trusting all proxies is safe only when the server can't be reached except through Cloudflare or Nginx on localhost. With ports still open to the world, list Cloudflare's ranges instead.

7. Caching without surprises#

By default Cloudflare caches static files (CSS, JS, images) and not HTML. Keep it that way for Laravel: HTML pages carry sessions and CSRF tokens.

Rule (Caching → Cache Rules)Why
Bypass cache for /admin*, /horizon*, /livewire*, /broadcasting*Dynamic, per-user
Cache /build/* for a long timeVite file names change on every build
Never "Cache Everything" on HTMLUsers would see each other's pages

After a deploy, Vite's hashed file names make purging unnecessary.

8. Firewall basics (free plan)#

SettingSuggestion
Security → Bots → Bot Fight ModeOn, unless it blocks your API clients or webhooks
WAF → Custom ruleChallenge /login from countries you never serve
Rate limitingProtect /login and /api (Laravel's throttle too)
Skip ruleLet your CI and uptime monitors through, if challenged

Git webhooks hit /cipi/webhook on your domain: don't challenge that path.

Troubleshooting#

You seeCauseFix
ERR_TOO_MANY_REDIRECTSSSL/TLS on FlexibleFull (strict)
525 SSL handshake failedNo certificate on the server for that namecipi ssl install (or add the alias first)
526 Invalid SSL certificateCertificate doesn't cover the name, or expiredsudo cipi ssl status, reissue
521 Web server is downNginx unreachable, or ports closed without a tunnelsudo cipi status, firewall
522 Connection timed outProvider firewall blocks CloudflareAllow 80/443
413 on large uploadsPlan's request size limitDirect-to-S3 uploads or a grey subdomain
Login loops, 419 errorsLaravel thinks it's on HTTPtrustProxies, APP_URL=https://…, config:cache
Every visitor has the same IPReal IP not configuredStep 6
Webhook deploys failBot protection challenges /cipi/webhookSkip rule for that path

Questions

Orange or grey cloud?

Grey (DNS only) sends visitors straight to your server: simplest, nothing in between. Orange (proxied) sends them through Cloudflare: CDN, DDoS protection, WAF, hidden server IP. Both work with Cipi; with orange, use SSL/TLS Full (strict).

Why do I get "too many redirects"?

SSL/TLS is set to Flexible: Cloudflare talks HTTP to your server, Cipi redirects to HTTPS, Cloudflare asks again over HTTP, forever. Set Full (strict).

Do I need Cloudflare for HTTPS?

No. Cipi issues free Let's Encrypt certificates for any domain. Cloudflare is needed only to automate wildcard certificates, or if you want its proxy features.

Can I use the free plan?

Yes. DNS, proxy, Universal SSL, basic WAF and DNS-01 certificates all work on the free plan.

Why does Laravel log Cloudflare's IP instead of the visitor's?

Behind the proxy, requests come from Cloudflare. Nginx must read the real IP from Cloudflare's header and Laravel must trust the proxy. See step 6.

Do WebSockets (Reverb) work through the proxy?

Yes, Cloudflare proxies WebSockets on the standard HTTPS port, which is what Cipi uses for Reverb.

Are uploads limited?

Through the proxy, request bodies are limited by your Cloudflare plan (100 MB on Free and Pro). For bigger uploads, upload directly to object storage with signed URLs, or use a grey-cloud subdomain.

Does a deep subdomain like a.b.example.com work?

Not with Cloudflare's free Universal SSL, which covers the apex and one level. Keep names one level deep, or buy an advanced certificate.

Try it on your own server

Free and open source. One command on a fresh Ubuntu 24.04 or 26.04 VPS.

wget -O - https://cipi.sh/setup.sh | bash
Read the quickstart