Bobcares

5 steps to solve “bad gateway” error in Plesk

by | Nov 21, 2018

I can’t access my Plesk panel. It shows a “Bad gateway” error. Something is wrong with my system. Please help!!

That was a recent support ticket we received at our Outsourced Technical Support services where we resolve support queries for web hosting providers.

Customer tried to login to his plesk panel. But, he was kicked out with the error “502 Bad Gateway“.

What can be the problem here?

Today, let’s see the top 5 reasons for the error “plesk bad gateway and how we fix them.

 

What is Plesk Bad Gateway error?

From Plesk version 12 onwards, Nginx is supported as a reverse proxy and most web hosts prefer this.

With reverse proxy, it accepts a request from the client, forwards it to Upstream server(server that can complete the request), and returns the server’s response to the client.

Plesk bad gateway errors occur when the proxy server receives an invalid response or no response from the upstream server.

Users will see this error when they access Plesk or perform any actions from plesk.

This error is cryptic and you feel like something is messed up but not sure where to start.

That’s where you need an expert to figure it out quickly and fix it permanently.

 

Reasons for Plesk Bad Gateway error? How to fix it?

To fix the error, we identify the cause of the error by checking and ruling out each possibility.

For that, our Hosting Engineers first examine the plesk web server logs and other server logs(/var/log/messages, /var/log/syslog, etc.) to identify why Plesk is not working properly.

For example, here’s a sample error message.

recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 123.123.123.123, server: , request: "POST <some url>

 

In our experience dealing with gateway errors, we’ve come across a number of reasons that can be the cause of this error.

1) Service errors

Plesk panel depends on 2 services sw-cp-server and sw-engine.

sw-cp-server” is the Plesk web server and “sw-engine” is the handler that generates Plesk web pages.

In some cases, these services may be stopped manually or failed to start after an update.

If these services are not running or not giving the desired results, bad gateway errors pop up.

Solution

Firstly, we check the status of these Plesk services on the server.

We then identify and fix the reason for the service downtime and start the service.

In Linux servers, we start the services using the below commands.

service sw-engine start
service sw-cp-server start

2) Configuration issues

We’ve seen cases where the Plesk services are running fine but it may not be properly configured to handle the incoming requests.

As a result, these services can timeout handling the incoming requests. This leads to “bad gateway” errors.

Solution

If the service is working fine, but the server logs shows timeout errors, we’ll fine tune the sw-cp-server config parameters like execution time, buffer sizes, timeout settings, etc.

But, these values should not be increased blindly as this can hog server resources.

So, our Hosting Support Specialists adjust the configuration parameters in accordance with the server resources.

Some of the parameters that we adjust in the sw-cp-server config file are :

fastcgi_buffers
fastcgi_buffer_size
fastcgi_read_timeout
fastcgi_send_timeout

3) Port blocks

General Plesk access ports are 8443 for secure or https connections and 8880 for http connections.

These ports can be further changed for security reasons. If the ports are not allowed for connections in the server firewall, the connectivity can fail and lead to bad gateway errors.

Solution

Our Hosting Engineers examine the configuration file to identify the correct ports on which the plesk service runs.

We then edit the firewall configuration to allow connections to these ports.

For instance, if the firewall is iptables, then we use the below commands to open the ports 8443 and 8880.

# 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

4) Fail2ban Firewall

Plesk uses IP address banning(Fail2ban) module to protect the server from brute force attacks.

In Plesk versions 12, 12.5 and Plesk Onyx, there is a bug that causes Fail2ban to block the server IP address itself.

As a result, when users access Plesk, Fail2ban reads all these requests from reverse proxy and interprets it as a hack attempt and blocks the access.

Result is “bad gateway” error.

Solution

This bug fix was already done in Plesk  version 17.5.

In such cases, our Plesk Support Specialists contact the web hosts and schedule a Plesk upgrade at off peak hours to reduce the downtime.

Also, to ensure the smooth flow of this process, we follow a set of pre-checks and post-checks on the server.

In case, an upgrade is not possible, we have an alternate solution.

We manually add the server IP address to Fail2ban’s list of Trusted IP addresses. This can be done from:

Tools&Settings > IP address Banning(Fail2ban) > Trusted IP Addresses

 

 

5) Version conflicts

This usually happens after Plesk upgrades.

Sometimes, the Plesk version may not be compatible with the versions of PHP, Mysql, MariaDB, etc. in the server that prompt for this error.

Solution

We diagnose the issue by analyzing the server logs and plesk web server logs.

In addition, we analyze the software requirements and re-configure the services to match the required version.

Conclusion

To sum up, plesk bad gateway errors can occur due to service errors, firewall restrictions, version conflicts, etc. Today, we’ve discussed the top 5 reasons for this error and how our Plesk Support Specialists fix them.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

SEE SERVER ADMIN PLANS

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF