Skip to content
PK Hosting

Using Cloudflare With Your Pakistan Hosting: Setup Without 522 and 504 Errors (2026)

PK Hosting TeamDate: 9 min read

Network cables and server lights representing DNS and CDN routing

You turned on Cloudflare because a colleague said it would speed up your shop, and within an hour the homepage showed 522, checkout threw 504, or wp-admin looped between HTTP and HTTPS. That sequence is common for Pakistani WordPress and WooCommerce sites — not because Cloudflare is broken, but because DNS, SSL mode and firewall rules were set in the wrong order for hosting that already includes a free DV certificate on PK Hosting.

This is a practical Cloudflare setup Pakistan guide for site owners who host with us (or any cPanel-style origin we provide). We do not resell Cloudflare and there is no one-click Cloudflare button in our panel; you manage Cloudflare in your own account. Our job is to give you a reachable server IP, working TLS on the origin, and logs when something fails. Yours is to point Cloudflare at that origin without strangling admin, cart or mail.

When Cloudflare is worth it — and when to leave it off

Cloudflare helps when you want their anycast DNS, optional orange-cloud proxy (CDN, caching, WAF), or DDoS absorption in front of a modest shared or VPS origin. It is less helpful when:

  • Your audience is mostly Pakistan and the site is already lean — a heavy theme and twenty plugins will stay slow at the origin; Cloudflare cannot fix PHP time (see speeding up WordPress and WooCommerce capacity planning).
  • You only need HTTPS — eligible PK Hosting plans already include a free DV certificate once DNS points here; read why HTTPS matters and issue the cert from your hosting service after routing is correct.
  • Your mail must stay simple — if you are not comfortable grey-clouding MX and autodiscover records, keeping DNS on ns1.pkhosting.com and ns2.pkhosting.com is often easier than mixing proxy and mail on the same zone.

Many teams still choose Cloudflare for WordPress/WooCommerce when they understand the trade-off: one more layer to configure, but useful caching and security when configured with exclusions.

Two DNS paths: Cloudflare nameservers vs PK Hosting nameservers

Path A — Cloudflare in front (proxy/CDN): Change the domain’s nameservers at the registrar to the pair Cloudflare assigns (for example ada.ns.cloudflare.com). Import or recreate DNS inside Cloudflare. Web A records for @ and www should point to the IPv4 address on your PK Hosting service page (or the documented hostname if that is what the panel shows). Toggle the orange cloud on for those web records if you want traffic proxied.

Path B — PK Hosting DNS only: Set nameservers to ns1.pkhosting.com and ns2.pkhosting.com at the registrar. Cloudflare’s proxy is not in play; you manage records in the PK Hosting dashboard. That is the right choice when you want one DNS pane for web, MX and TXT without a second login.

You cannot have both: if WHOIS still lists our nameservers, a Cloudflare account alone does nothing until delegation moves to Cloudflare. The reverse also holds — after Cloudflare nameservers propagate, edits in our DNS zone for that domain no longer affect the live internet until you switch back.

For Cloudflare .pk domain setups, nameserver changes go through the same registrar/PKNIC path as any .pk or .com.pk update. Registry and registrar caches can make that slower to visible globally than a .com at a big international registrar. Plan the cutover outside peak sales hours and verify with WHOIS or our WHOIS lookup before you declare victory. Step-by-step registrar context lives in how to point your domain to PK Hosting.

Ordered setup: connect Cloudflare to hosting without breaking mail

  1. Confirm hosting is live. Log in at https://www.pkhosting.com/login/, open the hosting service, and copy the server IPv4 (and any listed hostname). Billing should show paid before you repoint production DNS.
  2. Export existing DNS. Screenshot or export current A, AAAA, CNAME, MX, TXT (SPF, DKIM, DMARC) and autodiscover records. Missing MX after a nameserver swap is the fastest way to stop business mail.
  3. Add the site to Cloudflare and let it scan records. Review every row — scanners miss custom subdomains and stale parking A records.
  4. Set web records to the hosting IP. Root @ and www (A or flattened CNAME per Cloudflare’s UI) must target the PK Hosting server. Remove conflicting old-host A records.
  5. Grey-cloud mail-related names. MX, mail, autodiscover, and often ftp should be DNS only (grey cloud). Proxied SMTP is a common source of odd mail failures.
  6. Change nameservers at the registrar to Cloudflare’s pair. For .pk names, use the registrar/PKNIC interface you used to register — not an outdated reseller bookmark.
  7. Wait for delegation. Some resolvers update in minutes; others take hours. Do not toggle SSL modes every five minutes during propagation.
  8. Issue or confirm origin TLS. On PK Hosting, issue the free DV certificate from the hosting SSL section once DNS resolves to us. Cloudflare’s edge cert is separate; the origin must also present a valid cert for Full (strict).
  9. Set SSL/TLS mode to Full (strict). See the next section — do not stop at Flexible.
  10. Test without the proxy once. Grey-cloud the A record briefly or hit the origin IP with curl -I --resolve yourdomain.pk:443:YOUR_SERVER_IP https://yourdomain.pk/ from a machine you trust. Confirm HTTP 200/301 and a valid certificate before re-enabling the orange cloud.

A shorter checklist for the same flow is in our knowledge base article Use Cloudflare in front of PK Hosting.

SSL/TLS: use Full (strict), not Flexible

Cloudflare’s Flexible mode encrypts visitor → Cloudflare but speaks HTTP (or loose HTTPS) from Cloudflare → your origin. WordPress with “force HTTPS” plugins or server redirects often enters a loop: Cloudflare downgrades, WordPress upgrades, repeat. PK Hosting shared and WordPress plans include a free DV SSL certificate on the origin once DNS is correct — use it.

Recommended sequence:

  • Issue the DV cert on the hosting service (Let’s Encrypt validates against the hostname on our server).
  • In Cloudflare → SSL/TLS, choose Full (strict) so Cloudflare verifies the origin certificate.
  • Enable “Always Use HTTPS” in Cloudflare if you want sitewide redirects — avoid also forcing HTTPS in conflicting ways on the origin unless you know the plugin stack.
  • Fix mixed content (http:// assets on https:// pages) in the theme or database; strict mode will not hide insecure scripts.

Errors 525 (no valid SSL handshake to origin) and 526 (invalid origin cert) usually mean the certificate is missing, expired, or issued for the wrong name — fix origin TLS before tuning WordPress.

What 522, 504, 525 and 526 actually mean

These codes are Cloudflare-specific labels on top of whatever your server would have returned. Use them to decide whether to open Cloudflare or the hosting error log first.

Symptom → likely cause → first fix
What you seeMeaningCheck first
522 Connection timed outCloudflare could not complete a TCP connection to the origin IP on the expected port (usually 443 or 80).Wrong A record IP, server firewall blocking Cloudflare ranges, origin down, or hosting suspended. Verify IP in the service page; ping support with the domain if the account should be active.
504 Gateway timeoutCloudflare reached the origin but the application did not finish in time.Heavy admin-ajax or checkout plugin, PHP max execution, database lock, or origin overload. Test the same URL directly against the server IP; read the hosting error log and disable recent plugins.
525 SSL handshake failedOrigin did not present TLS Cloudflare could accept.Certificate not issued yet, wrong hostname on cert, or TLS disabled on the vhost. Issue DV SSL on PK Hosting, then retry Full (strict).
526 Invalid SSL certificateOrigin cert failed validation (expired, self-signed, hostname mismatch).Re-issue Let’s Encrypt from the panel; confirm the cert covers the apex and www you proxy.
Redirect loopToo many 301/302 hops between Cloudflare and WordPress.Often Flexible SSL plus WordPress HTTPS plugins. Move to Full (strict) and align redirect rules in one place only.
Challenge page on checkout or wp-adminBot fight mode, managed challenge, or “Under Attack” matching admin/cart paths.Add path exclusions (below); lower sensitivity on staging before production.

Origin test vs Cloudflare test: If the site loads at the server IP (with a hosts file or --resolve) but fails through Cloudflare, suspect DNS records, SSL mode, or a Cloudflare rule. If both fail, suspect PHP, disk, or database on the hosting account — open a ticket from the client login with the timestamp and URL.

WordPress and WooCommerce paths you must exclude

Security features that challenge every browser are toxic on interactive WordPress routes. Never apply Managed Challenge, “I’m Under Attack”, aggressive bot scores, or country blocks to:

  • /wp-admin/ and /wp-login.php
  • /wp-admin/admin-ajax.php
  • /wp-json/ (REST API — blocks break the block editor and many plugins)
  • WooCommerce cart, checkout, my-account, and /?wc-ajax= endpoints
  • Payment gateway return URLs (JazzCash, EasyPaisa, card gateways — whatever your plugin documents)

In Cloudflare, use WAF custom rules or Configuration Rules with skip/challenge bypass for those URI paths, or lower the security level for verified good bots only on public pages — not on admin. Test logged-out checkout in an incognito window after every WAF change.

Caching: what to cache and what to leave alone

Default Cloudflare caching helps static assets (CSS, JS, fonts, images). It hurts when HTML for cart, checkout or my-account is stored and served to the wrong shopper.

  • Create cache rules: bypass cache for /cart, /checkout, /my-account, and WooCommerce query strings you use in production.
  • Do not cache responses that set session cookies — WooCommerce sets cookies on pages that look “static”.
  • WordPress admin and preview URLs should always bypass.
  • After launch, run a test order with a real payment method (or sandbox mode) while watching both Cloudflare analytics and the store’s order list.

If only uncached WooCommerce pages are slow while static pages are fast through Cloudflare, the bottleneck is almost always origin PHP — too many plugins, slow queries, or a plan that needs more headroom. Compare tiers on shared hosting or move heavy stores toward VPS when you outgrow fair-use CPU; Cloudflare is not a substitute for cleaning the plugin list.

Troubleshooting checklist (print this)

  1. WHOIS shows the nameservers you intend (Cloudflare or PK Hosting — not an old host).
  2. Web A records point to the current IPv4 on the hosting service page — not a previous migration IP.
  3. MX and mail subdomains are grey-cloud (DNS only).
  4. Origin DV SSL is issued and valid; Cloudflare SSL mode is Full (strict).
  5. Site loads via direct origin test; if not, fix hosting before Cloudflare rules.
  6. No redirect loop when Flexible is disabled.
  7. WAF/challenge rules exclude wp-admin, admin-ajax, wp-json, cart, checkout, payment callbacks.
  8. Cache bypass on cart, checkout, my-account.
  9. Error log on the hosting account checked for 500/503 at the same timestamp as a 504.
  10. One plugin or theme change at a time when debugging 504 on admin-ajax.

Soft next step

If you have not moved DNS yet, start with hosting and a clean WordPress install on web hosting plans or WordPress hosting in Pakistan, issue the free SSL, then add Cloudflare when you have the IP and records written down. Need a second pair of eyes on a 522 that appeared after a sale? Email [email protected], call (042) 35692952, or send context through contact with the domain, a screenshot of Cloudflare SSL mode, and whether mail still works.

Frequently asked questions

Can I use Cloudflare with PK Hosting without changing nameservers to Cloudflare?

Only if the domain already uses Cloudflare nameservers. If nameservers remain ns1.pkhosting.com and ns2.pkhosting.com, Cloudflare is not proxying traffic — manage DNS in the PK Hosting dashboard instead, or delegate to Cloudflare first.

What SSL mode should I use for WordPress on PK Hosting behind Cloudflare?

Use Full (strict) after a valid DV certificate is issued on the origin. Flexible mode often causes redirect loops with WordPress HTTPS settings. Errors 525 and 526 point to fixing origin TLS, not lowering Cloudflare to Flexible.

Why does my Pakistani .pk site show Cloudflare 522 after I enabled the proxy?

522 means Cloudflare cannot connect to the origin IP. Confirm the A record matches the hosting service IPv4, the account is active, and the server responds on ports 80/443. Test the origin directly before changing WAF rules.

Should I cache WooCommerce checkout through Cloudflare?

No. Bypass cache for cart, checkout, my-account and wc-ajax endpoints. Cached checkout HTML can show another customer’s session state or break payment plugins.

Does PK Hosting integrate Cloudflare in the control panel?

No. You configure Cloudflare in your own Cloudflare account. PK Hosting provides the origin server, free DV SSL on eligible plans, and support for DNS either on our nameservers or at Cloudflare when you point A records correctly.

Keep learning

Related hosting guides

Browse all guides
We treat your site as ours

Let’s get your website online today

Compare plans, complete checkout, view invoices and manage payments on pkhosting.com.