How to Solve PrestaShop Server Down Problem (Error Code 521) – A Practical Security Approach?

How to Solve PrestaShop Server Down Problem (Error Code 521) – A Practical Security Approach?

How to Solve PrestaShop Server Down Problem (Error Code 521) – A Practical Security Approach

Recently, one of our customers reported an intermittent issue where their PrestaShop store occasionally displayed a “Web Server is Down” message, showing Error Code 521. Interestingly, when they refreshed the page (pressing F5), the site would return to normal.

At first glance, this seemed like a classic DDoS (Distributed Denial of Service) symptom, so we enabled “Under Attack Mode” in Cloudflare as a precaution. However, the problem continued to occur sporadically.


Investigation Process

We proceeded with a systematic troubleshooting approach:

  1. Application Logs
    We reviewed the PrestaShop prod.log and exception.log — no critical errors were detected.
  2. Web Server Logs
    We checked the Apache error.log and system-level syslog — again, everything appeared normal.
  3. Database Logs
    Finally, we inspected MySQL slow query log (mysql_slow.log), and here we found an important clue.
    Two tables stood out due to slow queries:

    • ps_connections
    • ps_guest

    Upon further investigation, we noticed that both tables had grown unexpectedly large. Moreover, a massive number of records had been inserted over the past few days.


Root Cause & Remediation

Conclusion:
The large size of ps_connections and ps_guest led to database slowdowns, which in turn affected page load times. When the response time exceeded the timeout threshold, Cloudflare returned Error 521.

Solution:
We removed outdated records from the impacted tables and optimized them:

SQL Commands to Clean Up the Tables

DELETE FROM ps_connections
WHERE date_add BETWEEN '2021-01-01 00:00:00' AND '2025-06-10 00:00:00';

DELETE FROM ps_guest
WHERE id_guest < 600;

OPTIMIZE TABLE ps_connections;
OPTIMIZE TABLE ps_guest;

ANALYZE TABLE ps_connections;
ANALYZE TABLE ps_guest;

Optional Cleanup

You may also clean up the following tables if they are large and unused:

  • ps_pageviewed
  • ps_log

Additional Security Tip: Protect Your Back Office

To further enhance security and reduce potential abuse:

  • Implement WAF (Web Application Firewall) rules to block unauthorized access to your PrestaShop Back Office.
  • Example WAF Rule:
    • Condition: URI Path contains /administrator2025
    • Condition: Country NOT IN your desired countries
    • Action: Block

This will significantly reduce unwanted login attempts and limit exposure to automated attacks.


Conclusion

If you’re facing intermittent Error 521 issues in PrestaShop with no apparent web server or application errors, it’s worth checking your database size and growth patterns. Large ps_connections and ps_guest tables can silently degrade performance.

Combining log analysis, database tuning, and WAF rules gives you a strong defense against such issues.



Start typing and press Enter to search

slot gacor dana slot deposit dana