Error code 520: 5 causes and how to fix them
Key takeaways:
- Error 520 happens when your website’s server doesn’t respond properly, causing Cloudflare to show an error instead of loading the site.
- Common causes include an overloaded server, security settings blocking Cloudflare, incorrect DNS settings, or issues with certain website files.
- You can fix the error by checking server logs, adjusting firewall settings, fixing DNS records, and ensuring your server is running smoothly.
If you’ve ever tried to visit a website and seen an Error 520 message, you’re not alone. This error is common, especially for sites using Cloudflare, and it can be frustrating when pages refuse to load properly. It usually happens when the web server doesn’t respond as expected, which leaves users stuck without access.
But what does it mean, and more importantly, how do you fix it? We’re going to break down the five most common reasons you see Error 520 and give you simple, easy-to-follow steps to get you back online.
What is Error code 520?
Error 520 is a common issue that happens when a website’s server doesn’t respond the way it should. This usually occurs when Cloudflare, a service that helps websites load faster and stay secure, tries to connect to the server but gets an unexpected or empty response.
In simple terms, the website’s server isn’t giving Cloudflare the information it needs, so instead of loading the page, you see an error message. This can happen for several reasons, like server overload, misconfigured settings, or firewall issues.
This is different from other 5xx errors, which usually have clearer causes. Let’s break down how Cloudflare interacts with your origin server and why this error happens.
How Cloudflare and your server communicate
- A visitor requests a page. Their browser asks Cloudflare to fetch your website.
- Cloudflare forwards the request. It acts as a middleman, sending the request to your server.
- Your origin server responds. Normally, your server sends back a webpage.
- Cloudflare delivers the response. The visitor sees your site load.
When everything works smoothly, your site loads fast and benefits from Cloudflare’s security and caching. But if the server sends back an unexpected or empty response, Cloudflare doesn’t know what to do and that’s when Error 520 happens.
5 common causes of Error code 520
Here are the most common reasons behind this error and what might be happening behind the scenes.
- Server-side issues. Your web server might be overloaded, misconfigured, or experiencing crashes, leading to an invalid response being sent to Cloudflare.
- Firewall or security software blocking cloudflare requests. Your firewall or security software might be blocking Cloudflare’s requests, misinterpreting them as threats. This can happen with Web Application Firewalls (WAFs), server firewalls, or DDoS protection tools.
- DNS configuration errors. Cloudflare relies on your DNS records to connect to your website. If these records are incorrect, Cloudflare may fail to retrieve a valid response.
- Corrupt .htaccess file or server rules. Misconfigured server rules or a corrupt .htaccess file can prevent proper responses from being sent to Cloudflare, leading to Error 520.
- Response header issues. Cloudflare expects properly formatted HTTP response headers from your server. If these are missing or malformed, it can trigger Error 520.
How to fix Error code 520: Step-by-step troubleshooting
Step 1. Check Cloudflare status & error logs
Before getting into fixes, make sure Cloudflare itself isn’t experiencing issues.
- Go to Cloudflare Status. See if Cloudflare is having outages.
- Check Cloudflare’s Error Logs. Cloudflare provides logs that might give more details on the error.
If Cloudflare is down. You’ll have to wait until their services are restored.
If only your site is affected. Move to the next step.
Step 2. Verify server response browser using devTools
Since Error 520 happens when Cloudflare gets an unexpected response, you need to check what response your server is sending.
Using Browser Developer Tools:
- Open your website in Chrome or Firefox.
- Press F12 (or right-click → “Inspect”).
- Go to the Network tab and refresh the page.
- Click on your site’s request and check the Headers tab.
If the response is missing key headers or is empty, move to the next steps.
Step 3. Whitelist Cloudflare’s IPs in your firewall
Your server’s firewall might be blocking Cloudflare, causing the error.
How to whitelist Cloudflare’s IPs:
- Log in to your hosting provider or server control panel.
- Open firewall settings (e.g., CSF, UFW, iptables).
- Add Cloudflare’s IP ranges to the allowlist. Find Cloudflare’s IPs here.
- Save changes and restart your firewall.
If your firewall was blocking Cloudflare, the error should be resolved now.
Step 4. Check and Fix DNS Configuration
If your DNS settings are incorrect, Cloudflare might not be able to find your server properly.
How to check:
- Log in to Cloudflare Dashboard → Go to DNS Settings.
- Make sure your A records point to the correct IP.
- If you’re using CNAME records, ensure they’re configured properly.
- Disable and re-enable Proxy Mode (orange cloud icon) to refresh DNS settings.
A DNS misconfiguration might have caused the issue, so this should fix it.
Step 5. Identify and fix faulty plugins or scripts
If you use WordPress, Joomla, or another CMS, a bad plugin, theme, or script might be breaking your site’s response.
How to troubleshoot:
- Disable all plugins.
- Check if the site loads without Error 520.
- If the error is gone, reactivate plugins one by one until you find the culprit.
If a plugin was causing the issue, replace or update it.
Step 6. Reset .htaccess file & server configuration
A corrupt .htaccess file or server rule can cause the error.
How to reset .htaccess in WordPress or Apache servers:
- Rename your .htaccess file to .htaccess_old in your site’s root folder.
- Reload your site.
- If the error is gone, create a new .htaccess file and add the default rules.
For Nginx or LiteSpeed users:
- Check server configuration files (nginx.conf, .user.ini).
- Look for unnecessary redirects or security rules.
Fixing your .htaccess file should fix major issues.
Step 7. Optimize server performance
If your server runs out of memory or crashes, Cloudflare might get an invalid response.
How to optimize:
- Increase PHP memory limits (if using WordPress or PHP apps).
- Optimize your database (clean up unused data).
- Reduce heavy scripts that slow down server response.
If server overload was the issue, these steps should help.
Quick troubleshooting summary table
Here’s a quick table summary for your troubleshooting needs.
Step | What to check | How to fix |
Step 1 | Check Cloudflare status & logs | Visit Cloudflare Status. |
Step 2 | Verify server response | Use cURL or browser DevTools to inspect responses. |
Step 3 | Firewall blocking Cloudflare | Whitelist Cloudflare’s IP addresses in firewall settings. |
Step 4 | DNS misconfiguration | Ensure A/CNAME records in Cloudflare point to the correct IP. |
Step 5 | Faulty plugins or scripts | Disable plugins/themes & test site. |
Step 6 | Corrupt .htaccess or server rules | Reset .htaccess or check Nginx/Apache settings. |
Step 7 | Server crashes or overload | Increase PHP memory, optimize database, reduce heavy scripts. |
How Error 520 differ from other 5xx errors
To put things in perspective, here’s a quick comparison of common 5xx errors, including Error 520:
Error Code | Meaning | Cause | Who needs to fix it? |
500 – Internal Server Error | Generic error for server-side issues | Server misconfigurations, bad scripts | Website owner or hosting provider |
502 – Bad Gateway | Invalid response between two servers | Gateway timeout, firewall issues, overloaded servers | Hosting provider or website owner |
503 –Service Unavailable | Server is temporarily unavailable | Maintenance, server overload | Hosting provider |
504 – Gateway Timeout | A server didn’t respond in time | Slow server response or Cloudflare timeout | Hosting provider or website owner |
520 – Unknown Error | Cloudflare got an unexpected response from the origin server | Server misconfigurations, firewalls blocking Cloudflare, bad response headers | Website owner or hosting provider |
Error 520 is unique because it’s specific to Cloudflare and other 5xx errors can happen with or without it. Understanding this difference will help you diagnose the issue more effectively.
How to prevent future 520 errors
Fixing Error 520 is great but preventing it from happening again is even better. Below are proactive steps you can take to keep your site running smoothly and avoid unexpected 520 errors in the future.
Keep your web server configurations optimized
Many 520 errors happen because of misconfigured servers, so keeping your origin web server properly optimized is crucial.
- Use stable server software versions. Running outdated or experimental versions of Apache, Nginx, or LiteSpeed can cause issues. Stick to stable releases.
- Limit heavy resource usage. High CPU or memory usage can cause crashes. Optimize scripts, reduce heavy queries, and enable caching.
- Check server logs regularly. Review Apache/Nginx logs or PHP error logs to detect early signs of failures before they become a problem.
If you use WordPress, install a caching plugin (like WP Rocket or W3 Total Cache) to reduce server load and prevent unexpected downtime.
You can also clear your website’s cached files in Cloudflare. Navigate to the Caching tab and select Purge Everything to ensure visitors see the most up-to-date content.
Implement firewall & security rules correctly
A misconfigured firewall can mistakenly block Cloudflare, leading to 520 errors. To prevent this:
- Whitelist Cloudflare’s IPs in your server’s firewall. Ensure that your CSF, UFW, or iptables firewall allows traffic from Cloudflare’s IP ranges.
- Review Web Application Firewall (WAF) settings. If you use a WAF like ModSecurity, make sure it’s not blocking Cloudflare requests.
- Use rate limiting wisely. Don’t set your rate limits too low, or Cloudflare’s multiple requests might get flagged as attacks.
If using Cloudflare’s WAF, configure rules to allow traffic from your own server and avoid accidental blocks.
Set up automated website monitoring
One of the best ways to prevent downtime is to catch errors early before they affect users.
- Use uptime monitoring tools. Services like UptimeRobot, Pingdom, or New Relic can alert you when your site goes down.
- Monitor response request headers. If Cloudflare is receiving incorrect headers, you can use server log monitoring tools (e.g., Loggly, Papertrail).
- Track Cloudflare Analytics. The Cloudflare Dashboard shows request logs that can help detect unusual patterns.
Set up UptimeRobot to send instant email or SMS alerts when your website is down, so you can act before visitors notice.
Maintain a clean & updated .htaccess file
A corrupt or over-complicated .htaccess file can cause unexpected issues.
- Keep redirect rules simple. Avoid complex redirect chains that might confuse Cloudflare.
- Backup & Test Changes. Always test updates in a staging environment before applying them live.
- Reset Default .htaccess. If you suspect it’s the issue, replace it with a default version and reapply necessary rules one by one.
If your .htaccess file has too many redirect rules, simplify them by using Cloudflare’s Page Rules instead of server-based redirects.
Optimize your DNS & Cloudflare settings
DNS misconfigurations can cause Cloudflare to fail to connect properly with your server.
- Check that your A Records point to the correct server. Incorrect DNS records can break Cloudflare’s connection.
- Use CNAME Flattening. If your site depends on CNAME records, enable CNAME flattening in Cloudflare for better stability.
- Avoid switching between Cloudflare’s Proxy & DNS Modes too often. Constantly toggling “Proxied” (orange cloud) and “DNS only” (grey cloud) can cause temporary connection issues.
If switching hosts, update Cloudflare’s DNS settings immediately to prevent a mismatch between the old and new IP addresses.
Keep web applications & plugins updated
If you run a WordPress, Joomla, Magento, or custom CMS, outdated plugins or extensions can create server-side errors.
- Regularly update plugins & themes. Old plugins may cause conflicts that break server responses.
- Check for incompatible plugins. Some plugins may interfere with Cloudflare’s caching or firewall rules.
- Use Cloudflare-Compatible plugins. Some security or caching plugins already integrate with Cloudflare (like WP Cloudflare Super Page Cache).
If your site is running WordPress, use Cloudflare’s official plugin to sync your settings and prevent conflicts.
Use a reliable hosting provider
Your web hosting provider plays a big role in preventing 520 errors.
- Choose a host that supports Cloudflare. Some hosting providers have built-in Cloudflare integration.
- Avoid cheap shared hosting for high-traffic sites. Overloaded shared servers often cause random crashes that lead to Cloudflare errors.
- Upgrade your server. If your site has grown, consider moving to VPS, cloud hosting, or dedicated servers for better performance.
The impact of error 520 on businesses
If your site frequently runs into Error 520, it could have long-term consequences. Let’s talk about how this error can impact your business and why fixing it fast is crucial.
- Lost revenue & sales. If customers can’t access your site, they can’t make purchases, book services, or complete transactions. For eCommerce sites, even short outages can mean thousands in lost sales.
- Damaged customer trust & reputation. Frequent errors make your site look unreliable. If visitors repeatedly encounter issues, they may lose trust in your brand and turn to competitors instead.
- SEO & search rankings drop. Search engines prioritize fast, reliable sites. If Google encounters errors while crawling your site, your rankings could decline, reducing organic traffic.
- Increased support requests & costs. When your site is down, customers flood support with complaints. This increases workload, raises operational costs, and shifts focus away from growth.
- Competitive disadvantage. If your site struggles with downtime while competitors’ sites run smoothly, you risk losing both customers and market share. A slow or unreliable website gives visitors an easy reason to leave.
Keep your website error 520 free
Error 520 can be a frustrating roadblock, but it’s entirely preventable with the right approach. By regularly monitoring your server’s performance, optimizing firewall and DNS settings, and keeping your software up to date, you can significantly reduce the chances of encountering this issue.
Proactive maintenance, such as reviewing error logs and ensuring your hosting environment is stable, can help keep your site running smoothly without unexpected downtime.
If you want to avoid technical headaches and ensure your site stays online, check out Domain.com for secure hosting and quality website security. We’ve got the tools to help. Don’t let a 520 error slow you down, get started today!
Frequently asked questions
The time it takes to fix a 520 error depends on the cause. Simple fixes like whitelisting Cloudflare IPs or adjusting Cloudflare DNS records can be done in minutes. However, if the error occurred is server-related, such as a misconfiguration or resource limits, it may take a few hours to diagnose and resolve, especially if you need help from your hosting provider.
If you fix it yourself, there’s no cost, just follow the troubleshooting steps in this guide. However, if you need professional help, developers may charge $50 to $200 per hour for diagnosing and fixing server issues. If the problem is due to server limitations, upgrading your hosting plan could cost $10 to $100+ per month. Hosting providers may assist for free if the issue is on their end, so check with them first.
It depends on the cause. If it’s a server issue (firewall blocking Cloudflare account, DNS misconfigurations, crashes), your hosting provider should help. If it’s caused by a plugin, theme, or misconfigured .htaccess file, the website owner or developer is responsible. Not sure? Start by contacting your hosting provider, they can check server logs and guide you. You can also contact Cloudflare support.