Question

Wordpress Eror 504/502 (occurs at certain hours)

Posted October 4, 2021 106 views
NginxWordPressLoad Balancing

Hello, friends. I have an unresolved 504/502 error problem. This error occurs at certain hours. Ussually at 10 A.M and 5 P.M (Western Indonesian Time). This error is characterized by increasing memory in cpu, load avg, disk I/O and bandwidth. The website could be accessed again if reload the nginx. My apologize for this inconvenience.

I have checked the active plugins on my website, but nothing seems to be the problem. What is the solution? I thank you for all the answers, it would be priceless thing for me.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
1 answer

Hi @SandyLightCyanSubmarine,

This error is usually caused by high load as you’ve found out. What you can do is try and optimize your WordPress website and your Droplet to see if that helps out.

Let’s start with Server Optimization.

When looking at Server/Droplet Optimization, there are a few necessary services/packages that are universal.

  • The first one would be Server-side caching. Server cache is an umbrella term covering a number of different types of caching. This includes Content Delivery Network (CDN) caching, object caching, and opcode caching. Depending on what you want to achieve you might need one or the other. Usually, though, you can have all 3 types of caching as it shouldn’t interfere with your Website/App. I won’t go into more details about what each caching does as this post will become 3 pages long. There are multiple documents providing services/packages for each of the server-type caching.

  • Next would be using PHP-FPM (if your Website is using PHP of course). PHP-FPM is an efficient method on how to minimize the memory consumption and rise the performance for the Websites with heavy traffic. It is significantly faster than traditional CGI-based methods in multi-user PHP environments.

  • Another solution would be Database Caching. A database cache supplements your primary database by removing unnecessary pressure on it, typically in the form of frequently accessed read data. The cache itself can live in a number of areas including your database, application or as a standalone layer. Usually, for this kind of caching is being used Redis.

Those were the basic optimizations on a server level, let’s start with your Website/App

If you are using a CMS like WordPress, Magento, Joomla, Opencart or anything of the same matter, there will be plugins/addons. These addons can be very powerful if used correctly. The most helpful plugins are:

  • Caching Plugins
  • Image Optimization Plugins
  • Plugins that reduce redirections/requests
  • Plugins that reduce the size of JS and CSS files.
  • More often than not, there are a lot of JS and CSS files that are not being used, removing those should work as well

If you are not using a CMS, you’ll need to try and do what these plugins are doing manually.

Usually, Websites/Apps are slow because of a couple of reasons which range from too many requests or big images to a bunch of unnecessarily big JS or CSS files. Optimizing these whether you are using a Plugin or doing it manually is enough.

If none of this helps, I’ll suggest upgrading your Droplet to have more CPU and RAM.

Additionally, try and add SWAP to your Droplet, it should help with the issues:

https://www.digitalocean.com/community/tutorials/how-to-add-swap-space-on-ubuntu-20-04

by Brian Boucheron
One way to guard against out-of-memory errors in applications is to add some swap space to your server. In this guide, we will cover how to add a swap file to an Ubuntu 20.04 server.