Cloudflare

Run the VMStack panel on a domain proxied by Cloudflare: the installer option, the visitor addresses, certificates, and what is not supported.

The panel can sit behind Cloudflare's proxy (the orange cloud). The installer needs to know, because a proxied domain resolves to Cloudflare's addresses instead of the server's, and because nginx must take the visitor's real address from Cloudflare's header.

Two ways to install#

DNS only during the install. Set the panel's record to DNS only (grey cloud) in Cloudflare, run the installer normally, then turn the proxy on. The installer then sees the server's own address in DNS and gets its certificate directly. Without --behind-cloudflare, though, nginx does not trust Cloudflare's header, so every visitor appears with a Cloudflare address: rate limits, logs and the panel's sign-in log are then per Cloudflare address, not per visitor. To fix that later, see Turn it on after the install.

Proxied, with --behind-cloudflare (recommended when the domain stays proxied):

curl -fsSL https://vmstack.eu/install.sh | bash -s -- --behind-cloudflare

Without the option, the installer stops with "panel.example.com is proxied by Cloudflare. Set it to DNS only for the install, or run with --behind-cloudflare."

What the option changes#

  • DNS check. Cloudflare's addresses in the domain's records are accepted. Any other address that is not the server's is still refused.
  • Visitor addresses. nginx trusts the CF-Connecting-IP header from Cloudflare's address ranges only (set_real_ip_from for each range, in /etc/nginx/conf.d/vmstack-cloudflare.conf). The panel, its rate limits, the sign-in log and the access log then see each visitor's own address.
  • Cloudflare's ranges are fetched from cloudflare.com at install and refreshed weekly by vmstack-panel-cfips.timer. When a fetch fails, the last good list stays; before the first fetch, a list built into the installer is used.
  • The setting is saved in /etc/vmstack/panel.conf (BEHIND_CLOUDFLARE=1), so repairs and updates keep it.

Certificates#

The installer still gets a Let's Encrypt certificate for the domain on the server, by the HTTP challenge. Cloudflare passes /.well-known/acme-challenge/ through to the server, and nginx answers the challenge on both port 80 and port 443, so Cloudflare's Always Use HTTPS does not break it. Renewals work the same way.

In Cloudflare, set the SSL/TLS encryption mode to Full (strict): the server has a certificate browsers trust, so Cloudflare can check it.

Console and API#

The console uses a WebSocket at wss://panel.example.com/relay/. Cloudflare proxies WebSockets, so it works through the proxy. The API answers at https://panel.example.com/api/; Cloudflare's own security features (bot checks, challenges) must not challenge API calls from your billing system, or they fail. If the panel's update check runs into a Cloudflare challenge page, it reports that the answer came from Cloudflare.

Nodes#

Nodes download the agent and its updates from https://panel.example.com/downloads/, which works through the proxy. The panel's own calls to nodes go out from the server directly, not through Cloudflare, so a node's firewall must allow the server's real address, not Cloudflare's.

Turn it on after the install#

To start using --behind-cloudflare on an installed panel, set it in the installer's configuration and write nginx's configuration again:

sed -i 's/^BEHIND_CLOUDFLARE=.*/BEHIND_CLOUDFLARE=1/' /etc/vmstack/panel.conf
vmstack-panel cfips
vmstack-panel repair

cfips fetches Cloudflare's ranges, writes nginx's real-address rules and reloads nginx; repair adds the weekly refresh timer. To turn it off again, set BEHIND_CLOUDFLARE=0 and run vmstack-panel repair: nginx stops trusting the header.

Not supported#

  • Cloudflare Tunnel. The installer does not set up cloudflared, and a panel reached only through a tunnel is not a tested setup.
  • Allowing ports 80 and 443 only from Cloudflare's ranges. The installer's firewall opens them to everyone.