Arama Yap Mesaj Submit
Request a Callback
+90
X
X

Select Your Currency

Turkish Lira $ US Dollar Euro
X
X

Select Your Currency

Turkish Lira $ US Dollar Euro

Contact Us

Location Halkali merkez neighborhood fatih st ozgur apt no 46 , Kucukcekmece , Istanbul , 34303 , TR
Cloudflare 521 Web Server Is Down: Fix with Nginx, Docker and SSL
Cloudflare 521, Nginx, Docker and SSL

Cloudflare 521 Web Server Is Down: Real Docker Portainer + Nginx + SSL Fix

This guide documents the real Cloudflare Error 521 Web Server Is Down incident we hit while publishing Portainer on portainer.ekasunucu.com from an Ubuntu 24.04 VPS. Portainer was healthy on 127.0.0.1:9443, but the public origin 443/reverse-proxy layer was not ready. We completed the origin path with Nginx, local testing and a Let's Encrypt certificate, and separately document the Certbot core24 timeout that occurred later.

Cloudflare 521Web Server Is DownCloudflare Error 521Portainer CloudflareNginx reverse proxyCloudflare Full strictCloudflare originDocker PortainerLet's EncryptCertbotUbuntu 24.04origin port 443EKA Sunucu
Ollama / Qwen3 / Open WebUI / Ubuntu 24.04
Visitor
  ↓
Cloudflare
  ↓ HTTPS :443
Nginx Origin
  ↓
https://127.0.0.1:9443
  ↓
Portainer

Before: no :443 → 521
After: Nginx + TLS → HTTPS 200
Ollama0.32.6Open WebUI0.11.0 test
13real WebP screenshots
3TR · EN · DE content
443public HTTPS
127.0.0.1AI service loopback
01Real Cloudflare 521 cause
02Origin :443 + Nginx reverse proxy
03Let's Encrypt + Full (strict)
04521 vs 522 vs 525 vs 526
00
Table of contents

Cloudflare 521 troubleshooting and resolution steps

  1. 01What does Cloudflare Error 521 Web Server Is Down mean?
  2. 02When you see 521, separate a broken backend from a broken origin web-server layer
  3. 03Confirm the Cloudflare DNS record points to the intended origin
  4. 04Verify that the origin listens on the port required by the Cloudflare SSL mode
  5. 05Use Nginx as the origin reverse proxy to the localhost Portainer 9443 backend
  6. 06Forward Host and WebSocket headers correctly through Nginx
  7. 07Validate the Nginx origin path locally with a Host header
  8. 08Do not confuse the Certbot core24 timeout with Cloudflare 521
  9. 09Deploy a Let's Encrypt certificate to Nginx and complete origin HTTPS
  10. 10Prefer Cloudflare Full (strict) after the origin HTTPS path is valid
  11. 11A firewall blocking Cloudflare IPs can produce the same 521 error
  12. 12Do not confuse 521 with 522, 525 or 526
  13. 13For recurring 521, check DNS → backend → Nginx → 443 → HTTPS in that order
01
Read the error correctly

What does Cloudflare Error 521 Web Server Is Down mean?

Cloudflare's current documentation defines 521 as the origin web server refusing connections from Cloudflare. The two common causes are an offline origin web server or Cloudflare requests being blocked at the origin.

When SSL/TLS mode is Full or Full (strict), Cloudflare connects to the origin over HTTPS, so the origin must actively listen for HTTPS. In our real Portainer incident the backend on 9443 was healthy but the public origin reverse-proxy/443 layer was not ready yet.

Command 1
Cloudflare Edge → Origin :443 → connection refused → 521
02
First split

When you see 521, separate a broken backend from a broken origin web-server layer

If Portainer itself is down, fix the container first. But if localhost 9443 returns HTTP 200 during a 521, the backend is healthy and the problem is higher in the stack: Nginx, TLS, firewall or the Cloudflare-to-origin path.

This distinction avoids the unsafe workaround of exposing the backend port publicly. We kept 9443 local and added an Nginx reverse proxy.

Command 1
docker ps --filter name='^/portainer$'
Command 2
curl -k -I https://127.0.0.1:9443
03
DNS check

Confirm the Cloudflare DNS record points to the intended origin

Before deeper 521 troubleshooting, confirm that the hostname resolves to the correct origin. A wrong A or AAAA record sends you to an unrelated server and makes every port/firewall check misleading.

We checked portainer.ekasunucu.com through Cloudflare and Google DNS. Temporarily switching a proxied record to DNS-only can simplify direct-origin troubleshooting, but it is a diagnostic option rather than a universal certificate requirement.

Command 1
dig +short A portainer.ekasunucu.com @1.1.1.1
Command 2
dig +short A portainer.ekasunucu.com @8.8.8.8
04
Origin port

Verify that the origin listens on the port required by the Cloudflare SSL mode

Cloudflare's 521 guidance explicitly says that when Full or Full (strict) is used, the origin web-server application must be bound to the HTTPS port required by that mode. For normal HTTPS origin traffic this is port 443.

Portainer itself served HTTPS only on localhost 9443. Cloudflare cannot directly use that private backend mapping; a public origin web server on 443 was needed.

Command 1
ss -lntp | grep -E ':443|:9443'
05
Solution layer

Use Nginx as the origin reverse proxy to the localhost Portainer 9443 backend

Instead of making the Portainer application port public, we used Nginx as the origin web server. Requests for portainer.ekasunucu.com are proxied to https://127.0.0.1:9443.

Because the local Portainer upstream uses a self-signed certificate, proxy_ssl_verify off is limited to that localhost hop. Public origin TLS is terminated by Nginx with a Let's Encrypt certificate.

Command 1
apt-get update && apt-get install -y nginx
Command 2
proxy_pass https://127.0.0.1:9443;
Command 3
proxy_ssl_verify off;
06
Portainer UI connections

Forward Host and WebSocket headers correctly through Nginx

Portainer's web UI benefits from preserving standard proxy and WebSocket upgrade headers. We forwarded HTTP/1.1, Upgrade and Connection along with Host and X-Forwarded headers.

This is separate from the basic 521 connection refusal. If 521 disappears but the UI has live-connection problems, review the reverse-proxy headers.

Command 1
proxy_http_version 1.1;
Command 2
proxy_set_header Host $host;
Command 3
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
Command 4
proxy_set_header Upgrade $http_upgrade;
Command 5
proxy_set_header Connection $connection_upgrade;
07
Test before Cloudflare

Validate the Nginx origin path locally with a Host header

Testing the origin locally before re-enabling Cloudflare shortens troubleshooting. nginx -t, service status and a local Host-header request validate separate layers.

After our reverse proxy was installed, the local Nginx request returned 200, proving the Portainer backend and Nginx proxy chain worked independently of Cloudflare.

Command 1
nginx -t
Command 2
systemctl is-active nginx
Command 3
curl -sS -o /dev/null -w '%{http_code}\n' -H 'Host: portainer.ekasunucu.com' http://127.0.0.1/
08
Real second failure

Do not confuse the Certbot core24 timeout with Cloudflare 521

During Let's Encrypt setup, our real Certbot snap installation timed out while downloading core24. That was not a continuation of the Cloudflare 521 problem; it was a separate outbound network timeout from the VPS to the snap CDN.

After network access recovered, retrying the snap/Certbot process succeeded. Treat simultaneous error messages as separate layers until proven otherwise.

Command 1
snap install certbot --classic
Command 2
snap changes
Command 3
journalctl -u snapd --no-pager -n 100
09
Origin HTTPS

Deploy a Let's Encrypt certificate to Nginx and complete origin HTTPS

Once the Nginx HTTP vhost worked, Certbot --nginx obtained a certificate for portainer.ekasunucu.com. After deployment the origin could serve a valid certificate on port 443.

That completes the core prerequisites for certificate-validating Cloudflare modes: reachable HTTPS on 443, an unexpired certificate and a hostname match.

Command 1
certbot --nginx -d portainer.ekasunucu.com
Command 2
curl -I https://portainer.ekasunucu.com
Command 3
certbot renew --dry-run
10
Cloudflare SSL/TLS

Prefer Cloudflare Full (strict) after the origin HTTPS path is valid

Cloudflare's current guidance recommends Full (strict) whenever possible. It encrypts the edge-to-origin connection and validates the origin certificate, including validity and hostname matching.

A publicly trusted certificate such as Let's Encrypt can satisfy those requirements. Verify origin 443 and the certificate chain before selecting Full (strict), otherwise you may move from a 521 into a different SSL error.

Command 1
Visitor HTTPS → Cloudflare → HTTPS + certificate validation → Nginx origin :443
11
521 is not always Nginx

A firewall blocking Cloudflare IPs can produce the same 521 error

Our real case was an origin reverse-proxy problem, but Cloudflare documents blocked Cloudflare requests as another common 521 cause. Origin firewalls, rate limits or security software can refuse legitimate Cloudflare connections.

If Nginx is healthy on 443 and direct origin tests work but 521 continues, inspect firewall, fail2ban, CSF/LFD, rate limiting or provider security layers. Use Cloudflare's current official IP ranges instead of guessing individual addresses.

Command 1
tail -n 100 /var/log/nginx/error.log
Command 2
journalctl -u nginx --no-pager -n 100
Command 3
iptables -S
Command 4
nft list ruleset
12
Use the right code

Do not confuse 521 with 522, 525 or 526

521 means the origin refused the Cloudflare connection. 522 is an origin connection timeout. 525 is an SSL handshake failure, while 526 indicates an invalid origin certificate under certificate validation.

The troubleshooting direction changes with the code: web server/listener/firewall for 521, reachability/timeouts for 522, and TLS handshake/certificate chain for 525/526.

Command 1
521 → connection refused / origin down
Command 2
522 → origin connection timeout
Command 3
525 → SSL handshake failed
Command 4
526 → invalid SSL certificate
13
60-second checklist

For recurring 521, check DNS → backend → Nginx → 443 → HTTPS in that order

The fastest troubleshooting method is to isolate each layer. Check DNS first, then the localhost backend, then Nginx config/service, the 443 listener and finally the real HTTPS/domain path.

Do not solve 521 by exposing the backend port. Complete the correct origin web-server layer instead.

Command 1
dig +short A portainer.ekasunucu.com
Command 2
curl -k -I https://127.0.0.1:9443
Command 3
nginx -t && systemctl is-active nginx
Command 4
ss -lntp | grep -E ':443|:9443'
Command 5
curl -I https://portainer.ekasunucu.com
Command 6
tail -n 100 /var/log/nginx/error.log
Production checklist

Cloudflare origin and reverse-proxy security checklist

Do not expose backend container ports publicly just to fix 521.
Verify the origin listens on the port required by the SSL mode.
Use a valid hostname-matching origin certificate for Full (strict).
Check firewall and rate-limit rules for blocked Cloudflare IP ranges.
Monitor Nginx error and access logs during troubleshooting.
Test local backend health separately from public origin health.
Preserve WebSocket Upgrade headers for applications that need them.
Run Certbot renewal dry-runs.
Re-check SSL/TLS mode after Cloudflare proxy changes.
Differentiate 521, 522, 525 and 526 instead of treating them as one issue.
R
Official sources

Official Cloudflare, Nginx and TLS resources

+
EKA Sunucu

Related EKA Sunucu Cloudflare, Docker and Portainer guides

?
FAQ

Frequently asked questions about Cloudflare 521 Web Server Is Down

What does Cloudflare 521 mean?

It means Cloudflare's connection to the origin web server was refused by the origin.

What are the common causes of 521?

Cloudflare documents an offline origin web server and blocked Cloudflare requests as the two common causes.

Why can Portainer work locally while Cloudflare shows 521?

The backend can be healthy on localhost 9443 while the public origin web-server layer on 443 is missing or refusing connections.

Which origin port is needed for Full or Full (strict)?

For standard HTTPS origin traffic, the origin web server must actively accept HTTPS on port 443.

Should I expose Portainer 9443 to fix 521?

No. We kept 9443 local and published the service through Nginx.

Which upstream did Nginx use for Portainer?

https://127.0.0.1:9443.

Why was proxy_ssl_verify off used?

Only for the localhost Portainer self-signed upstream; public origin TLS was terminated at Nginx with Let's Encrypt.

Is switching Cloudflare to DNS-only mandatory?

No. It can simplify troubleshooting and direct-origin testing, but it is not universally required for certificate issuance.

Was the Certbot core24 timeout part of the 521 problem?

No. It was a separate outbound TCP timeout to the Snap CDN.

When should Full (strict) be used?

Prefer it when the origin serves a valid, unexpired certificate matching the hostname on HTTPS.

What is the difference between 521 and 522?

521 is a refused origin connection; 522 is a timeout while contacting the origin.

What is the difference between 521 and 526?

521 is an origin connection refusal; 526 is an invalid origin certificate under certificate validation.

What if Nginx is healthy but 521 continues?

Inspect firewalls, fail2ban/CSF, rate limits and rules blocking Cloudflare IP ranges.

What is the fastest 521 checklist?

Check DNS, localhost backend, Nginx config/service, port 443 listener, origin HTTPS and error logs.

EKA YAZILIM VE BİLİŞİM SİSTEMLERİ

Need a Linux VPS for Cloudflare + Nginx + Docker?

Run Portainer, n8n, Open WebUI and other self-hosted services behind Nginx, TLS and Cloudflare on EKA Sunucu Linux VPS.

Updated: 10.08.2026
View Linux VPS PlansLinux & VPS Guides
Top