How to Solve the 502 Bad Gateway Error in Plesk?

How to Solve the 502 Bad Gateway Error in Plesk?

At times, when logging into your Plesk Panel, you’ll be automatically logged out of the panel with an error reading “502 Bad Gateway”. With many companies adopting Plesk as their preferred web hosting automation software, admins managing Plesk would be seeing this error more often. In this article, learn what causes this error and how to solve it.

plesk23.png


What Causes the Bad Gateway Error?

If you’re using Plesk 12 and onwards, then you should know that Nginx is used for reverse proxy. And many web hosts are preferring this approach.

With Nginx, Plesk accepts the requests made by the client before forwarding it to Upstream server. Then it receives the response and forwards it to the client.

You get the 502 Bad Gateway error when the Nginx proxy server doesn’t receive a response from the upstream server or gets an invalid response.

Users who try to access Plesk in such cases will get the gateway error. This error looks cryptic with no additional information on what to do.

How to Fix the 502 Bad Gateway Error?

The gateway error will impact your workflow with users not being able to access your services. Therefore, you must act quickly to solve the error. To get started, you need to pinpoint what caused the error.

Server logs is a great place to get started. You can navigate into /var/log/messages or /var/log/syslog to see an error something like this:

Code:
recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 123.123.123.123, server: , request: "POST <some url>
Here are some of the common reasons for this error:

There are Service Errors

For Plesk panel to run successfully, it depends on two services, which are sw-cp-server and sw-engine. The former is the Plesk web server while the latter is a handler that generates web pages.

At times, either one or both the services might be stopped, which triggers the 502 bad gateway error.

Solution

To fix the service errors, you need to check the status of the server services. You can find the reasons for the downtime and then restart the service using the following command on Linux:

Code:
service sw-engine start
service sw-cp-server start
There are problems with Configuration

If your services are running fine, then the problem might be with the configuration instead. The services might not be properly configured to handle the requests.

Solution

In the server logs, you’ll get a confirmation that the configuration is the problem.

To fix the problem, check the parameters of the sw-cp-server file like execution time, buffer sizes, and timeout settings.

Some of the parameters to adjust are:

Code:
fastcgi_buffers
fastcgi_buffer_size
fastcgi_read_timeout
fastcgi_send_timeout
The Port was blocked

There are ports that enable the connection. For secure or https connection, the access port is generally 8443, while for http connection, it’s 8880.

If the ports are not allowed to connect inside the server firewall, then you’ll see the bad gateway error.

Solution

To fix this error, edit the firewall configuration. This will allow the connections to the ports.

For iptables firewall, use the following commands to open port 8443 and 8880 respectively:

Code:
# iptables -I INPUT -p tcp --dport 8443 -m state --state NEW -j ACCEPT
# iptables -I INPUT -p tcp --dport 8880 -m state --state NEW -j ACCEPT
Firewall Error

Plesk uses the Fail2ban module to protect the server against attacks like brute force attack. It has been seen that there’s a bug that causes Fail2ban to block the default server IP address. So you’ll get the bad gateway error.

Solution

The Plesk team fixed the bug in version 17.5. So the best way to fix it is upgrade to version 17.5.

But if you want to keep using the existing version, then manually add the IP address in the Fail2ban Trusted IP addresses list. You need to visit the Tools & Settings >> IP address Banning(Fail2ban) >> Trusted IP Addresses

trustedip.png


There are conflicting versions

At times, the Plesk version does not match with that of PHP, MySQL, and MariaDB. In such cases too, you’re likely to get the bad gateway error.

Solution

To fix the version conflicting issues, check the software requirements of both the software and ensure they match. An upgrade to either or both of the software might solve the error as well.

So that’s how you fix the 502 bad gateway error. For further assistance, contact your hosting provider.
Author
kumkumsharma
Views
57
First release
Last update
Rating
0.00 star(s) 0 ratings

More resources from kumkumsharma

Top