Last time, I got surprising error messages with all the site’s images. I was hosting the static assets, including media with MaxCDN, and they worked well. However, sometimes when you change something including the server or the IP, your web hosting may blacklist the MaxCDN network from accessing your images and make a copy of them.
502 bad gateway Nginx
Please note that the error is not related to Nginx, it can appear with Lightspeed, Apache and other web servers.
What caused the 502 Bad Gateway?
The reason is a firewall that missed the list of IP addresses of any CDN or files sharing services. That’s the real issues, but there are always solutions for any problem.
If you got 502 bad gateway image errors with WordPress, Drupal or any other site software and you use MaxCDN, then, you need to modify the firewall settings or ask your web hosting provider to do that for you.
MaxCDN is one of the largest CDN networks in the world, they have thousands of servers across different countries. Unfortunately, when they add new servers, the IP address is not added to hosting services. As a result, the Web Firewall won’t be able to know that the new IP is from a CDN. When the server request the file it gets nothing as a blocked access.
I recommend contacting your company and ask them to whitelist the MaxCDN IP addresses listed below:
If this list is not working, then a new IP address was added and you can find all their IP blocks updated.
How to investigate your images and why they are not showing in WordPress or any other software? All you need is to Traceroote your image requests. You can Traceroote any address on Mac or Windows and that way, you can get detailed information about the error.
On Mac OS, for example, you can run a Traceroote by launching Network Utility. But first, lick the search icon spotlight in your Mac, then, type Network Utility and click on it. Next, choose the Traceroote tab. Enter the exact URL of any of your images that are not showing correctly in the browser, and click the scan button.
When the scan is complete, look for error details, and if you couldn’t find what all that code means, copy all the code and send it to your hosting’s technical customer support. That way, you gave them more details about the issue and they have all the Traceroote.
For Windows computers, follow this tutorial my Microsoft. It shows what you need as steps.
If you still unable to solve the problem, then there is something strange with your images or media files. The best thing you can do is scan your files for malware and codes. It’s right that the 502 bad gateway errors are related to server connection. But sometimes, plugins can come with wrong configurations and users can modify the settings by mistake, especially with caching plugins like W3 Total Cache, Super Cache, WP Rocket, and others.
In this case, try to disable the caching plugin and clear your browser cache, then check your images again. If it didn’t work, disable all your WordPress plugins at once or one by one, until you find the one that caused the problem.
I hope this fixed your problem of images on your blog or website. If you’ve fixed the issue with other ways, let me know and I’ll add your solution.