
Fastly can load-balance a Magento shop on its own. You add every Magento web node as a backend, group them in a director, attach a health check, and Fastly spreads cache misses across the healthy nodes. The load balancing guide describes exactly this setup, and Fastly stops sending requests to backends marked sick.
The catch is in how a backend is defined. A Fastly backend is an address: a hostname, IPv4 or IPv6 that Fastly's POPs connect to over the internet. If Fastly balances across four Magento nodes, all four need a public address and an open port. Every one of those machines holds the Magento code base, app/etc/env.php with database and Redis credentials, and the encryption key. On a B2B Magento project we worked on, that was the part of the default setup we did not want.
Why Fastly cannot just reach a private network
There is no "private endpoint" option in Fastly comparable to what some cloud CDNs offer. The closest product is Origin Connect: a physical cross-connect between your servers and a Fastly shield POP. It requires Enterprise support, servers in the same data center as that POP and a publicly routed ASN, and if the interconnect fails, Fastly falls back to public internet transit. So even with Origin Connect, the origin still has to accept connections from the internet. For a typical Magento shop on rented or cloud servers it is not an option at all.
Whatever Fastly talks to is internet-facing. The only question is which machine that is.
In network terms, that machine belongs in a DMZ (demilitarized zone): a separate network segment between the internet and the internal network, with a firewall on each side. The internet can reach only the ports the DMZ exposes, and the DMZ can reach only the specific internal services it needs. If a server in the DMZ is compromised, the attacker still has to get through the second firewall to reach databases and code. That only helps if the DMZ holds as little of value as possible.
Option 1: Magento nodes as Fastly backends
This is the setup the Fastly documentation leads you to.
What you get:
- No extra hop between Fastly and PHP.
- Fastly health-checks each node individually and routes around a broken one.
- Nothing extra to run.
What it costs:
- Every Magento node sits in the DMZ, together with its code and credentials. A vulnerability in the web server, PHP or a Magento module is reachable on each of them.
- Firewall rules, TLS certificates and OS hardening have to be correct on every node, and stay correct when you add a node during a sale.
- If a node's IP leaks (old DNS records, outgoing mail headers, an error page), attackers can send requests straight to it and skip whatever you do at Fastly, WAF rules included.
Option 2: one entry load balancer, Magento in a private network
Here Fastly has exactly one backend: a load balancer with a public address, and it is the only machine in the DMZ. The Magento nodes and the database are in the internal network, have only private addresses and accept connections from that load balancer only. The load balancer spreads requests across the front nodes when there is more than one.

This is the same path Adobe enforces on its own platform. For Adobe Commerce on cloud infrastructure, all requests must follow the path Fastly > Load Balancer > application instances, and direct access to the origin is blocked ("origin cloaking").
What you get:
- One public machine instead of one per Magento node. It runs no PHP and holds no Magento code or credentials.
- Magento nodes can be added or replaced without touching Fastly or the firewall facing the internet.
- One place to enforce "only Fastly may connect" (more on that below).
What it costs:
- An extra server to run, patch and monitor.
- It is the single entry point for the whole shop. If it goes down, the shop is down for every uncached request, no matter how many Magento nodes are healthy.
- Fastly's health check now sees the load balancer, not the individual nodes. Node health becomes the load balancer's job.
We accepted the single entry point as the price for keeping Magento off the internet. Redundancy for the load balancer itself is a separate topic and not covered here.
Choosing the entry server: HAProxy or nginx
Do not add Varnish here. Fastly already is the full-page cache, and Fastly's configuration language, VCL, comes from Varnish. A second Varnish layer adds another cache to invalidate and nothing else.
HAProxy is built for this one job. Active health checks are part of the free version: the check parameter on a server line makes HAProxy poll the server on a fixed interval. The Runtime API can put a node into drain state before a deployment, without reloading the configuration. The downside is one more tool with its own configuration syntax for the team to learn.
nginx is a web server that can also load-balance. Magento teams usually know it already, since Magento ships an nginx sample configuration. The limitation is health checking: NGINX Open Source has passive health checks only. It marks a node as failed after real user requests to it fail, and the active health_check directive is an NGINX Plus feature. A node that answers with errors is noticed only when customers hit it.
If the team is comfortable with HAProxy, it is the better tool for this position. If the choice is between a well-understood nginx and a half-understood HAProxy, nginx with tuned max_fails and fail_timeout is a reasonable trade.
Making sure only your Fastly service gets in
Moving the public surface to one load balancer is half of the work. The load balancer must also refuse everything that does not come from your Fastly service. Three layers, from weakest to strongest.
Layer 1: allow only Fastly's IP ranges
Fastly publishes its address ranges at api.fastly.com/public-ip-list for exactly this purpose: firewall rules for connections from Fastly to your origin. Changes are announced in advance on the Fastly status page.
curl -s https://api.fastly.com/public-ip-list \
| jq -r '.addresses[], .ipv6_addresses[]' > /etc/haproxy/fastly-ips.lstPut the same list into the network firewall or cloud security group, so non-Fastly traffic never reaches the load balancer process at all. This is what we run as the baseline.
It is not enough on its own. The list contains all Fastly-owned ranges, so it lets in every Fastly service, including one that someone else configures with your load balancer's IP as its backend. That request arrives from a Fastly address and passes the allowlist, while your VCL rules and WAF settings never ran on it.
Layer 2: a secret header from your service
Your Fastly service adds a header with a long random value to every request it sends to the backend. The load balancer rejects requests without it. AWS documents the same combination for CloudFront: an IP allowlist together with header inspection so that only your distributions reach the origin.
In Fastly, keep the value in an edge dictionary and set it on the backend request in a VCL snippet for vcl_miss and vcl_pass:
set bereq.http.X-Origin-Auth = table.lookup(origin_secrets, "lb_token");HAProxy checks both the source address and the header, then removes the header before passing the request to Magento:
frontend fastly_in
bind :443 ssl crt /etc/haproxy/certs/origin.pem
acl from_fastly src -f /etc/haproxy/fastly-ips.lst
acl has_token req.hdr(X-Origin-Auth) -m str "${ORIGIN_TOKEN}"
http-request deny unless from_fastly has_token
http-request del-header X-Origin-Auth
default_backend magento_web
backend magento_web
balance roundrobin
option httpchk GET /health_check.php
server web1 10.0.1.11:80 check
server web2 10.0.1.12:80 check/health_check.php is the health check script that comes with Magento in pub/.
The nginx equivalent uses a geo block for the IP list (each line <range> 1;) and passive checks on the upstream:
geo $from_fastly {
default 0;
include /etc/nginx/fastly-ips.conf;
}
upstream magento_web {
server 10.0.1.11:80 max_fails=3 fail_timeout=10s;
server 10.0.1.12:80 max_fails=3 fail_timeout=10s;
}
server {
listen 443 ssl;
# ssl_certificate ... ;
if ($from_fastly = 0) { return 403; }
if ($http_x_origin_auth != "replace-with-long-random-value") { return 403; }
location / {
proxy_set_header Host $host;
proxy_set_header X-Origin-Auth "";
proxy_pass http://magento_web;
}
}The header is a shared secret. Send it only over TLS between Fastly and the load balancer, keep it out of logs, and plan how to rotate it: accept the old and the new value for a while, switch the dictionary, then drop the old value.
Layer 3: a client certificate (mTLS)
Instead of a header, Fastly can authenticate itself with a TLS client certificate. The Fastly backend has ssl_client_cert and ssl_client_key fields for a certificate it presents to the origin. The load balancer then requires a certificate signed by your own CA: ca-file ... verify required on the HAProxy bind line, or ssl_client_certificate with ssl_verify_client on in nginx.
A stolen header value can be replayed from anywhere. A client certificate needs the private key, which lives only in your Fastly service configuration. The cost is certificate management: a private CA, expiry dates to track, and a rotation procedure you have actually tested.
The admin panel stays off this path
The Magento admin is not cached and is used by a handful of people, so it does not need Fastly. We serve it on a separate hostname that does not go through the public Fastly service, and restrict that hostname to known networks. That keeps /admin out of the attack surface of the storefront entirely, instead of protecting it with path rules inside the same service.
When the extra server is worth it
If the shop runs on a single Magento node, Fastly already has one backend, and hardening that node directly costs less than running another machine. Once there are two or more front nodes, adding them all to Fastly multiplies the public machines that hold your code and credentials. One entry load balancer, Fastly IP allowlist plus a secret header or client certificate, and Magento on private addresses keeps the internet-facing part to one server that has nothing worth stealing on it, at the price of that server being the point the whole shop depends on.
