How Can I Solve 502 Error Bad Gateway from Cloudflare?

By on August 17th, 2018

502 Bad Gateway means our network is not able to connect with your server for communication. The 502 Bad Gateway error is an HTTP status code which indicates that one server on the internet received an invalid response from another server.

In some cases, this error is returned by Cloudflare before contacting your origin server, and in that case, the error page should be like this.

502 bad gateway


The name “cloudflare-nginx” appears at the bottom of the error message indicating that the error is coming from Cloudflare. If you do not see this, this error is “not” coming from Cloudflare, and it is coming from origin server which looks like given below.

502 bad gateway


How the 502 Error Appears

Different web servers do show this error differently because this error can be customized by each website. Here are some common ways you might see it.

#502 Bad Gateway

# 502 Server Error: The server encountered a temporary error and could not complete your request.

#Temporary Error (502)

#502 Service Temporarily Overloaded

# HTTP Error 502 – Bad Gateway

#Bad Gateway: The proxy server received an invalid response from an upstream server

#502 Proxy Error


Cause of 502 Bad Gateway Errors

1) Domain name not resolvable

The domain name is not pointing to the correct IP or it does not point to any IP this problem may happen. Also, DNS propagation could take some time to make changes in DNS setting. It may take 24 to 48 hours to make reflect which is dependent upon the TTL defined per record on the DNS.

2)server down

The origin server is not reachable, this may due to the server is down for some reason or there is no communication to the server given.

3) Firewall blocks

A firewall interrupts the communication between the edge servers and the origin server. This may be caused by security plugins of your CMS.As a part of DDOS protection and mitigation process or due to some strict firewall rules servers can be blocked from accessing the original server.


What to do after getting 502 Bad Gateway error

1)If you got 502 bad gateway error you should check your IP address in the zone management, click on setting and make sure that the given IP is correct or not. If the IP address incorrectly, you need to update the origin IP in the Pull Zone Configuration to match the new IP, clear your zone cache. This should fix the problem.

2) By using a ping test or trace-route, verify if your server is reachable or not.

3) If the IP address is correct to check your firewall rules if you are seeing unusual drops.


Errors Like 502 Bad Gateway

Error messages are related to the “502 Bad Gateway error” is given below:

500 Internal Server Error

503 Service Unavailable

504 Gateway Timeout


If you need any further help please do reach our support department.



9 Responses to “How Can I Solve 502 Error Bad Gateway from Cloudflare?”

  1. THOMAS LEE says:

    Ray ID: 530b02cf28bdb5a6
    Your IP address: 2601:3c1:4100:4470:e094:2347:ac8:225a
    Error reference number: 502
    Cloudflare Location: Memphis

  2. Jaco Prinsloo says:

    I keep on getting the 502 Bad Gateway message via both my phone and my computer. Please assist in this regard.

  3. dan says:

    Was watching My Hero Academia and while waiting for the next episode to start my browser changed to….

    Bad gateway
    The web server reported a bad gateway error.

    Ray ID: 57fe37d13fe13fc3
    Your IP address:
    Error reference number: 502
    Cloudflare Location: Montréal

  4. Fedilyn says:

    Can you help me please I badly need it

  5. Olli says:

    It gave me the wrong IP how do I fix that

  6. Hhuuyyy says:

    Its only the owner website proplem not the visitor

Leave a Reply