Worried about the Magento 504 gateway timeout error on your website?
Usually, this occurs when the load balancer being unable to obtain a request from the webserver. And the reasons triggering it can vary.
At Bobcares, we often receive requests to solve this Magento errors as part of our Server Management Services.
Today, let’s discuss this error in detail and see how our Support Engineers fix it for our customers.
Why Magento 504 gateway timeout error occurs?
A 504 Gateway Timeout Error indicates that a web server attempting to load a page and did not get a timely response from the server.
Usually, this error means the webserver is down or not functioning properly.
This problem is most commonly caused when the Web Front and Back-Ends have a problem with IP communication.
Recently one of our customers contacted us with this error. When he tried to access his website and it returned the error message like this:
2 Reasons for Magento 504 gateway timeout error.
Mostly, the following are the two possible reasons for a 504 Gateway timeout error in Magento.
- The firewall drop: A firewall reject would cause a reset and immediate termination of the connection.
- The origin server is down or not working properly.
How we fix the Magento 504 gateway timeout error.?
Let’s now discuss some scenarios in which this error occurs and see how our Support Engineers fix it efficiently.
1. Clear the browser cache/Magento cache.
Whenever we make any changes to the Magento website, they will not appear unless we clear the application’s cache.
So it’s a mandatory step to first clear the browser cache and the Magento cache.
To clear the Magento cache, (through the Admin Panel)
-
- We go to the Magento admin panel.
- Then go to System -> Cache Management -> Flush Cache Storage
For manually clearing the Magento cache:
To clear the cache, we simply delete everything from the var/cache/ directory and then reload the website. Magento keeps its cache in the var/cache/ folder located inside the Magento installation directory.
2. Exceeding PHP limits
In a similar way, Magento 504 gateway timeout error occurs due to PHP limits too.
Here, the PHP goes out of memory when the website code base is extremely big.
In such cases, we increase the PHP memory limits in the php.ini file.
To do this,
- We update the below values in the php.ini file.
upload_max_filesize:1000M
max_execution_time:18000
memory_limit:2048M
max_input_time:18000
max_input_vars:3000
post_max_size:1000M
2. And then save the php.ini file.
3. Then we restart Apache service
On a CentOS server : service httpd restart
In Ubuntu: service apache2 restart
Moreover, if the customer is using NGINX webserver, we increase the below values in Nginx conf file at /etc/nginx/nginx.conf
fastcgi_buffers 8128k;
proxy_read_timeout 600;
fastcgi_buffer_size 256k;
fastcgi_read_timeout 600;
This resolves the 504 gateway time out error for our customers.
3. Fix faulty firewall configurations.
Sometimes a faulty firewall configuration will cause the Magento 504 gateway timeout error. So our Dedicated Engineers ask our customers to check the firewall configuration or disable it temporarily. This can easily isolate the firewall problem.
4. Check for any DNS changes
If the customer recently changed host servers or moved the website to a different IP address, this could cause the website to serve its visitors a 504 Gateway Timeout Error page.
The website won’t be up and running until these DNS changes take full effect, which can take a few hours.
So we wait for the completion of the DNS propagation delay.
5. High load on the server.
When the store receives more traffic than it can handle, it returns the 504 gateway timeout error in Magento.
So the high load/traffic on the server caused this gateway time out error.
In this case, we ask the customers to check the high load on the server and optimize the server to handle these visitors. This includes service configuration tweaking, adding server resources, etc.
6. Locked session
Another most common cause of 504 error is a locked session. It is a built-in feature of Magento that locks the session until the page load is complete.
The side effect of this locked session is that if we launch a very long-running process, the session will remain locked until that completes.
As a result, the website becomes completely inaccessible.
So we verify the issue by opening the site in an incognito window.
To solve this issue we recommend our customers to run long-running Magento processes by command line or scheduled task. We ask them to avoid web browser for such time consuming tasks.
[Need more assistance to fix Magento 504 error?- We’ll help you.]
Conclusion
In short, the Magento 504 gateway timeout error occurs when the load balancer is unable to obtain a request from a webserver. Today’s writeup discussed this error in detail and we saw how our Support Engineers fix it for customers.
Hello,
I’ve set below value but still getting 504 gateway timeout error when refresh Magento 2 cache.
upload_max_filesize:1000M
max_execution_time:18000
memory_limit:2048M
max_input_time:18000
max_input_vars:3000
post_max_size:1000M
Can you please know-how can get rid of this issue?
Hello Jignesh,
Looks like your Magento website needs custom configuration values to avoid the gateway timeout error. We’ll be happy to talk to you on chat (click on the icon at right-bottom).
Hello Sijin,
Let’s talk on chat.