Most Nginx reload guides stop at “run nginx -s reload and nothing drops.” That is only half the job. A production reverse proxy in front of real traffic also has to terminate TLS your visitors trust, speak HTTP/3, log real visitor IPs instead of CDN addresses, and survive a bad configuration push without taking the site down with it. This tutorial builds that proxy: Nginx on Ubuntu 24.04, sitting behind Cloudflare, with graceful reloads treated as the default way to change anything.
How to Build a Zero Downtime Nginx Reverse Proxy with Cloudflare SSL and HTTP 3
By the end you will build a zero downtime nginx reverse proxy with Cloudflare SSL and HTTP 3 in front of an application listening on 127.0.0.1:3000, and you will be able to swap its configuration and certificates without dropping a connection. The architecture has three tiers:
- Edge: Cloudflare’s anycast network terminates visitor HTTPS, absorbs DDoS traffic, and caches what it can at the edge.
- Origin: Nginx on your VPS accepts the proxied traffic, terminates origin TLS, and serves HTTP/2 and HTTP/3.
- Application: your services (Node.js, PHP-FPM, Docker containers) bound to loopback, never exposed directly to the internet.
Before you start: the Cloudflare side
Three settings on the Cloudflare side decide whether the origin configuration below works at all. First, the DNS record for your hostname must be proxied (the orange cloud), or none of the edge behavior applies and your origin IP is public. Second, set the SSL/TLS encryption mode to Full (strict). The Flexible mode, which talks to your origin over plain HTTP, is the single most common cause of infinite redirect loops behind Cloudflare, because your app sees an HTTP request and keeps redirecting it to HTTPS. Third, generate an Origin CA certificate in the Cloudflare dashboard (SSL/TLS, then Origin Server) and install it on the VPS. Full (strict) validates this certificate; visitors never see it, because Cloudflare presents its own edge certificate to browsers.
On the VPS firewall, allow TCP 80 and 443 plus UDP 443. HTTP/3 runs over QUIC, which uses UDP, and a forgotten UDP rule is the most common reason HTTP/3 silently never activates. If you want the origin reachable only through Cloudflare, restrict those ports to Cloudflare’s published IP ranges and consider Authenticated Origin Pulls for a stronger guarantee. If you are still deciding whether Cloudflare is the right edge at all, our Cloudflare vs Fastly vs Bunny CDN comparison covers the trade-offs before you commit.
The Nginx configuration blueprint
One version note first: HTTP/3 support requires nginx 1.25 or newer from the mainline branch, or a build compiled with the QUIC module. Check yours with nginx -V and look for --with-http_v3_module. If it is missing, install the mainline package from the nginx.org repository instead of the default Ubuntu build. Then create the virtual host at /etc/nginx/conf.d/app.conf:
server {
listen 80;
listen 443 ssl;
listen 443 quic reuseport;
http2 on;
http3 on;
server_name api.example.com;
# Origin certificate issued by Cloudflare
ssl_certificate /etc/ssl/certs/origin.pem;
ssl_certificate_key /etc/ssl/private/origin.key;
ssl_protocols TLSv1.2 TLSv1.3;
# Advertise HTTP/3 to browsers
add_header Alt-Svc 'h3=":443"; ma=86400' always;
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
# WebSocket support and keep-alive
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
# Forward the real client IP from Cloudflare
proxy_set_header Host $host;
proxy_set_header X-Real-IP $http_cf_connecting_ip;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_connect_timeout 60s;
proxy_send_timeout 60s;
proxy_read_timeout 60s;
}
}
Two details in this config are easy to miss. The Alt-Svc header is what tells browsers that HTTP/3 exists; without it the QUIC listener sits idle, because clients only upgrade to QUIC after being told it is available. And reuseport on the QUIC listener lets multiple worker processes share the UDP socket, which keeps connection handling balanced under load.
Restore real visitor IPs
By default, your logs will show Cloudflare’s addresses rather than your visitors’. Nginx’s real_ip module fixes this, but only trust the header when the request actually came from Cloudflare’s ranges. Put the following in /etc/nginx/conf.d/cloudflare.conf and refresh it when Cloudflare updates its published list:
set_real_ip_from 173.245.48.0/20;
set_real_ip_from 103.21.244.0/22;
set_real_ip_from 103.22.200.0/22;
set_real_ip_from 103.31.4.0/22;
set_real_ip_from 141.101.64.0/18;
set_real_ip_from 108.162.192.0/18;
set_real_ip_from 190.93.240.0/20;
set_real_ip_from 188.114.96.0/20;
set_real_ip_from 197.234.240.0/22;
set_real_ip_from 198.41.128.0/17;
set_real_ip_from 162.158.0.0/15;
set_real_ip_from 104.16.0.0/13;
set_real_ip_from 104.24.0.0/14;
set_real_ip_from 172.64.0.0/13;
set_real_ip_from 131.0.72.0/22;
real_ip_header CF-Connecting-IP;
With this in place, $remote_addr becomes the real visitor address everywhere downstream: access logs, rate limiting, and any geo or abuse logic in your application.
Zero-downtime reloads, step by step
Never run systemctl restart nginx on a live proxy. A restart stops the master process and drops connections mid-flight. A reload is a different mechanism entirely: the master process reads the new configuration, starts a fresh set of worker processes with it, and tells the old workers to finish their current requests and then exit. Existing connections are never touched, and long-lived ones such as WebSockets keep running on the old workers until they close naturally. The safe sequence is always the same:
# 1. Validate the new configuration before anything changes
sudo nginx -t
# 2. Graceful reload: old workers drain, new workers take over
sudo nginx -s reload
Step one is not optional. nginx -t validates the new configuration before a single process changes; if validation fails, the running workers keep serving the old, valid config and your site never notices the mistake. Keep the previous version of every config file (version control works fine), so a semantic error, meaning a config that validates but does the wrong thing, can be reverted with the same test-and-reload sequence. Once this is muscle memory, automate it: a CI job that tests configuration on every change and reloads on merge removes the human error entirely, and our guide to building a CI/CD pipeline with GitHub Actions shows the shape of that workflow.
The same sequence rotates certificates. Install the new origin certificate and key alongside the old ones, point ssl_certificate and ssl_certificate_key at the new files, then test and reload. The old workers keep serving the previous configuration until the new workers are live, so visitors never see an expired or half-installed certificate. Put the renewal date on a calendar with weeks to spare: an origin certificate that lapses behind Cloudflare shows up as a 526 error for every visitor at once.
Reloads make configuration changes free, but application deploys are the other half of zero downtime. Run the new app version on a second port, flip the proxy_pass target, reload, and flip back if the new version misbehaves. That is the blue-green pattern, covered in depth in our blue-green vs canary deployments guide.
Verify it actually worked
Trust, but verify from outside the server:
curl -I -sSL https://api.example.com | grep -iE "HTTP|alt-svc"
Know the boundary of the technique: a reload swaps configuration, not the nginx binary. Upgrading nginx itself, or fixing a module that fails to load, still needs a package install and a service restart, so schedule those for your quietest window and lean on Cloudflare’s edge cache to soften the few seconds involved.
The response should carry an alt-svc header advertising h3. If your curl build supports HTTP/3, curl --http3 -I https://api.example.com confirms the QUIC handshake itself. Check that the UDP listener exists with ss -ulnp | grep 443, and watch the access log while reloading under real traffic: there should be no spike in 502 responses during the switch. For proof over days rather than minutes, point an external monitor at the site; our roundup of uptime monitoring tools compares the common options.
Troubleshooting
Most readers arrive here after searching some variant of “how build zero downtime nginx reverse proxy cloudflare ssl http” because one of these five problems just bit them:
| Symptom | Likely cause | Fix |
|---|---|---|
| 502 Bad Gateway after a change | App is down or the proxy_pass port is wrong | Curl the upstream directly on loopback to isolate it |
| Infinite redirect loop | Cloudflare SSL mode is set to Flexible | Switch to Full (strict) and install an origin certificate |
| Cloudflare error 525 or 526 | Origin certificate missing, expired, or mismatched | Reinstall the Origin CA certificate and check the ssl_certificate paths |
| HTTP/3 is never used | UDP 443 blocked, nginx too old, or Alt-Svc missing | Open UDP 443, check nginx -V, confirm the header with curl |
| Logs show Cloudflare IPs | The real_ip block is missing | Add the cloudflare.conf ranges from the section above |
When one VPS in front of everything stops being enough, these patterns move with you: Nginx is also the most widely used Kubernetes ingress, and our Kubernetes ingress controller comparison covers how the trade-offs change at that scale. You will find more tech tutorials in the same spirit across this site: short on theory, long on configuration you can paste, test, and adapt.