• Please be aware: Kaspersky Anti-Virus has been deprecated
    With the upgrade to Plesk Obsidian 18.0.64, "Kaspersky Anti-Virus for Servers" will be automatically removed from the servers it is installed on. We recommend that you migrate to Sophos Anti-Virus for Servers.
  • The Horde webmail has been deprecated. Its complete removal is scheduled for April 2025. For details and recommended actions, see the Feature and Deprecation Plan.
  • We’re working on enhancing the Monitoring feature in Plesk, and we could really use your expertise! If you’re open to sharing your experiences with server and website monitoring or providing feedback, we’d love to have a one-hour online meeting with you.

502 bad gateway - nginx

Franco

Regular Pleskian
Hello,

my config is Plesk 12.5, apache 2.2 with nginx (no fpm-php), php 7.0.4 on all wordpress sites.
The system is quite stable and secured with fail2ban, mod_security etc., I rarely see attacks and other bugs these days (touch wood).

The only thing is this ancient problem I carry from the beginning of times (there was another ticket of mine about this a while back): systematically after reboot or at random times (average once per week, but unpredicatably) all my sites go down with 502 bad gateway. If I am around the fix is easy and straightforward: go to Plesk, tools&settings, firewall, disable all rules, enable all rules. That's it.

I have been searching and searching to get to the root cause: what is changing the network to cause this? What is touching the firewall rules and for what reason? Nothing in the nginx log, apache log, websites log, no warnings, no errors, just a blackout. If the firewall rules change is there a log somewhere?

In here I saw a suggestion to stop/start apache on a regular basis https://talk.plesk.com/threads/502-bad-gateway-error-on-all-domains.337351/ but I don't think it's my case as the 502 happens directly and systematically after a reboot.

Can somebody point me to the right direction, please?

Regards
Franco
 
Hello,

my config is Plesk 12.5, apache 2.2 with nginx (no fpm-php), php 7.0.4 on all wordpress sites.
The system is quite stable and secured with fail2ban, mod_security etc., I rarely see attacks and other bugs these days (touch wood).

The only thing is this ancient problem I carry from the beginning of times (there was another ticket of mine about this a while back): systematically after reboot or at random times (average once per week, but unpredicatably) all my sites go down with 502 bad gateway. If I am around the fix is easy and straightforward: go to Plesk, tools&settings, firewall, disable all rules, enable all rules. That's it.

I have been searching and searching to get to the root cause: what is changing the network to cause this? What is touching the firewall rules and for what reason? Nothing in the nginx log, apache log, websites log, no warnings, no errors, just a blackout. If the firewall rules change is there a log somewhere?

In here I saw a suggestion to stop/start apache on a regular basis https://talk.plesk.com/threads/502-bad-gateway-error-on-all-domains.337351/ but I don't think it's my case as the 502 happens directly and systematically after a reboot.

Can somebody point me to the right direction, please?

Regards
Franco

@Franco,

There are many explanations for this behavior and, even though you do not have fpm enabled, it all boils down to the same: problems with socket connections to the Apache backbone.

First of all, you should check that you have applied MU25, or verify that the packages

libapache2-mod-proxy-psa-2.4.7
psa-phpfpm-configurator-1.0.0

are up-to-date, in specific the mod_proxy package.

You can simply run the (command line) autoinstaller, with the advantage that all micro-updates are applied and all packages are updated to the latest version.

Second, have a look at https://talk.plesk.com/threads/potential-fpm-errors-after-update-mu25-solution.337375/#post-798622.

Third, do not emphasize the "firewall solution", since it is probably unrelated to the root cause of the problem.

Finally and in general, note that a 502 error code can be the endresult of many things, but the common root cause of the problem is that Apache is "overloading": Apache is still busy (executing one or more processes), Apache uses "too much" resources, Apache is associated with resource allocation failures and so on and so further.

The only thing you can do about that is to reduce the number of (loaded) modules, assign more memory, increase the execution time and/or reboot from time to time.

Apache always will remain a relatively memory hungry web server: this is also the reason why Nginx is handy (some tasks are not assigned to Apache, but to the efficient Nginx).

Anyway, hope the above helps a bit.


Regards
 
@PriyanA
thank you for the suggestion; my symptoms are not the same, no issue when I modify a plan setting, but I run the suggested procedure, just in case.

@trialotto
thank you for your help: I run the autoinstaller successfully and I suppose all my MU are ok now (although I was already on the latest plesk update).
At the next reboot I will see if things have improved.

However, I maintain my 'firewall' (network) position as I do not have any overload of apache or low memory or any resource related issue. Things just hang indefinitely and permanently. And a reboot does not help, on the contrary, it causes it 100% of times. Next time, I will try and restart apache and/or nginx before applying my firewall fix, although there isn't generally a lot of time to think when all your sites are unavailable...

Of course, i am quite nervous about it because I have no idea of what effects my empyrical-found-by-chance-after-hours-of-desperation firewall fix has and why, as I have no exotic rules or anything that could explain it. Next time it might not work and I'd be lost.

Regards
 
@Franco,

If you are "nervous" about the whole issue, just start a conversation with me and we will see what we can do.

Regards....
 
Seems like the problem am having :( ..... i tried taking off some sites leaving only 2 and that 2 has been online for 3 days now without going off. just enabled the 3rd moved the rest to namecheap.... anymore offline thingy am off to my previous setup :cool:
 
@trialotto,
thank you for your availability; I will wait for the next occurrence or I will reboot and, if problem confirmed even after all those updates, I will contact you.
Best,
F.
 
@Franco,

No problem, happy to be of some assistance, if I can help.

Note that a reboot is not always necessary, you can also try to restart FPM service first (note: there are multiple versions) and try to restart psa service in the second place.

In essence, a reboot is "the option of last resort": if you can prevent that, do prevent it.

Regards....
 
In this case I'd reboot to trigger the problem, instead of waiting for the issue to appear randomly.
Please note that, as mentioned earlier, I'm not running FPM, the procedure you pointed at was useful to get all MU applied, but I could not complete it because I have no FPM process to restart. I'd like to, though, but I never managed to get it working (I get 404 not found - nginx on the domain when I chose the option on the Plesk console - hosting settings).
 
Back
Top