Error 502 Bad Gateway trying to log into WP dashboard

Hello! One of my client sites is giving me a 502 error when I try to log in at /wp-admin. The site looks ok from the front end. I cleared my browser cache and still get the same error (see below). I could use some suggestions on what might be causing this problem and how I can restore access to my WP admin dashboard.

Recent changes? Yesterday I updated the site to the current WP version and I pasted a code snippet into a Header/Footer code manager plugin for a Constant Contact form. However, that didn't seem to cause any problems while I was working on the site yesterday. I did not have trouble until today. Thanks for your help!

This is the error I get in browser when I try to login:
ERROR 502 - BAD GATEWAY
Why am I seeing this page?
The server that your request has reached is acting as a gateway or proxy to fulfil the request made by your client.

Web Browser => Web Front-End => Web Back-End

This server (Web Front-End) received an invalid response from an upstream (Web Back-End) server it accessed to fulfil the request.

In most cases this will not mean that the upstream server is down, but rather that the upstream server and the gateway/proxy do not agree on the protocol for exchanging data.

This problem is most commonly caused when there is a problem with IP communications between the Web Front and Back-Ends. Before you attempt to resolve this problem you should clear your browser cache completely.

Our support staff will be happy to assist you in resolving this issue. Please contact our Live Support or reply to any Tickets you may have received from our technicians for further assistance.

  • Adam Czajczyk

    Hello Heather,

    I hope you're well today and thank you for your question!

    Usually, the "502" error is related - "under the hood" - to some resource issues. An example scenario would be: a site's doing some tasks by calling wp-ajax multiple times and server blocks those calls as too frequent or those calls make db go down etc. As a result the error shows up. But there might be many other reasons for this too.

    Since you didn't share the code that you added to the site, I have no way of telling for sure whether this code is causing it or not so I'd suggest starting with the simple test:

    - access the site (WP install) using FTP
    - go to /wp-content/plugins folder
    - rename the folder of that Header&Footer plugin that you used to inject your code to some non-standard but recognizable name (e.g. add "_off" suffix to the folder name)
    - clear browser caches and see if you can access the site.

    If that helps, it would mean that indeed this code (or other one added via that plugin) is a culprit.

    If it doesn't help, move on to WP debugging. To do this:

    - access the site via FTP (you can use cPanel's "File Manager" alternatively too)
    - edit "wp-config.php" file of the site, adding following lines to it:

    define( 'WP_DEBUG', true );
    define( 'WP_DEBUG_LOG', true );
    define( 'WP_DEBUG_DISPLAY', false);

    Make sure that these lines are above "/* That's all, stop editing */" line in a file.

    - after you added them, try accessing your site a couple of times
    - after that access the server again and look for file named "debug.log" inside the "/wp-content" folder of your WP install
    - download this file, rename it to "debug.txt" and attach to your response here.

    Hopefully, that file will give me some additional clues on what is happening with the site.

    Best regards,
    Adam

  • Heather

    Hello Adam,
    Thank you for your help. I got back to this issue today and when I logged into the site, it worked so I figured the problem had been temporary. But after working in WP and doing some plugin updates, the same 502 error occurred. I have attached the debug log for you. I'd be grateful for any help you can provide to prevent this from happening. I'm not a programmer, so I know just enough to find my way around and do small things, but not major troubleshooting. Thank you so much.

  • Predrag Dubajic

    Hi Heather,

    Since you were able to access your site again but the issue returned, it's most likely some server related issue as Adam mentioned before.
    So, your site was "cooling down" and after that you were able to access it again, but while you were doing stuff in backend one of your plugins or theme was probably firing up some stuff that caused your site to hit server limits and you were "locked out" again.

    The debug log only comes with Warnings and Notices, and those are usually not enough to stop the site from working properly but it's still worth checking since they are all referring to "Far Future Expiry Header" plugin.
    I see that the plugin does some similar stuff as Hummingbird so it might be a conflict between the two.

    I would suggest disabling the plugin and also check your .htaccess file and make sure that you don't have rules for GZIP Compression from both Hummingbird and Far Future Expiry Header in there, you should only have rules from one of them.

    If the issue is still there after that I would suggest getting in touch with your hosting provider as they can check the server logs and give you more precise information about what's causing the error.

    Let us know how it goes.

    Best regards,
    Predrag

  • Heather

    Hello again! Thank you for the ideas. I am now able to login to the WP admin dashboard, but when I try to load the Plugins list page, I get the 502 bad gateway error. So I can't disable/delete the plugin from the dashboard without being able to load that page. I have ftp access, and have renamed the Far Future folder, but I still can't load the Plugins page. I checked my htaccess file and I see gzip rules, Far Future rules, and also some Leverage Page Caching rules. Is it safe to share my htaccess file here, or can I provide it privately or have someone help me on a non-public conversation?

  • Predrag Dubajic

    Hi Heather,

    If there's a conflict with Hummingbird and Far Future it probably won't be resolved by disabling/renaming Far Future plugin as the rules are already added and those are not removed on deactivation.

    You can edit your .htaccess file and just replace the entire code there with the default .htaccess rules, you can get those from here:
    https://codex.wordpress.org/htaccess

    Just make sure that you have a backup of your current .htaccess file before making these changes.

    If that doesn't help it would best to get in touch with your hosting provider as the 502 error is server related and they can check the server logs to get more information about the actual cause of the issue.

    Best regards,
    Predrag

  • Heather

    Thank you! I replaced the contents of the htaccess file with the default content. That allowed me to login and load the Plugins page properly from the WP dashboard. Via ftp, I restored the name of the Far Future Expiry plugin and then deleted it from the Plugins control panel. For now, things seem stable. Thanks for your help! I'll call this case solved, at least as far as I have been able to see today.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.