Troubleshooting Common HTTP Errors

In this post, let’s have a look at common HTTP errors and how to troubleshoot them. HTTP error messages are classified into:

  • 1XX – Informational
  • 2XX – Success
  • 3XX – Redirect
  • 4XX – Client error
  • 5XX – Server error

Since we want to look at errors or problems, we’ll skip straight to 4XX and 5XX errors. The common ones are listed below.

400 – Bad Request

This indicates the request wasn’t properly structured or there was something wrong with the request. In most cases, it could be a browser or cookie related issue. If we still have issues after switching browsers and clearing cookies, we may want to look at how the request was formed.

401 – Unauthorized

This indicates whatever we are trying to access requires proper authorization. Either we provided incorrect credentials or our current user is simply not authorized to access this resource.

403 – Forbidden

This indicates we don’t have the right permission to access the requested resource. If the file we’re trying to access doesn’t have correct permissions, we can change it using chmod.

If file permissions are okay, it’s possible .htaccess could be denying access to specific IP ranges or we’re trying to access an empty directory that doesn’t have a default index file.

One of the potential solutions is to whitelist the IP address requesting this resource (to make sure that particular IP is not blocked).

404 – Not Found

This is the most common HTTP error. We may have mistyped the site address or the file that we’re requesting is simply not present.

500 – Internal Server Error

This is a generic server side error. We don’t know what went wrong and so we may have to do a couple of checks before we locate the issue. For example, what was the last change we did on the site before we started seeing this error? It could be changes to the PHP code or a new plugin/theme install on WordPress. We may need to look into error logs.

502 – Bad Gateway

This indicates the server is a gateway/proxy server and is not receiving a valid response from the backend server (which should be fulfilling this request). If this proxy server is a load balancer, check if backend server(s) are healthy.

503 – Service Unavailable

It could mean the server is overloaded or under maintenance. 503 says the service is temporarily unavailable and it’ll become available at some point.

We can check if it is overloaded by loading the site multiple times. If it loads a few times, it could mean the server needs more CPU or memory resources to handle the incoming requests.

We can also check analytics or other monitoring tools to see if there was a spike in the incoming requests.

504 – Gateway Timeout

It means that the gateway/proxy did not receive a response from the backend server within a specfic time period.

It could mean there’s a problem wtih network connectivity between the servers, or that the backend server is too slow or the timeout duration is too short.

In any case, for all 5XX error messages, we may still need to go through general troubleshooting steps mentioned under error 500, like checking PHP code, latest changes, looking at error logs, etc.

References

Digital Ocean: https://www.digitalocean.com/community/tutorials/how-to-troubleshoot-common-http-error-codes

Mozilla: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status

Wiki: https://en.wikipedia.org/wiki/List_of_HTTP_status_codes

HTTP Statuses: https://httpstatuses.com/

What is DNS?

In one line – It is Internet’s phone directory. DNS is what translates/resolves domain names (like Google.com) to an IP Address.

That is, it maps domain names to IP addresses. Without DNS, you’d have to remember IP address of every single website.

Source: https://www.appneta.com/

Ok so how does it work? Let’s understand with the help of an example:

  1. You type in Google.com in your browser and hit enter.
  2. Your computer then tries to find an IP address of Google.com.
    1. It checks the browser cache first.
    2. If not found, it checks your system cache.
    3. If not found, it’ll check your router’s cache.
    4. Still not found? It’ll send that request to your ISP (internet service provider).
      1. Your ISP will most likely have it but if it doesn’t have a record, your request now will be sent to one of the 13 root servers. (Note: there aren’t 13 physical servers but hundreds of servers across the world maintained by 13 entities).
      2. The root server gives an IP address of the TLD (top level domain) server. In case of Google.com, the TLD is .com and so your ISP gets an IP address of the .com TLD server.
      3. Your ISP now asks the TLD server for Google.com’s IP. The TLD server returns an IP of the authoritative DNS server.
      4. Finally ISP contacts the authoritative DNS server and gets Google.com’s IP address.
    5. Once your ISP has the IP address of Google.com, it’ll send it back to your router. Your router sends it back to your system and your system gives it to your browser. At each step, a copy of this record will be cached/stored.
  3. Your browser then makes a request to that IP (and starts to establish TCP connection, SSL/TLS connection, request web pages, etc).

Note: Your ISP server acted as a recursor or recursive resolver. That is, even if it didn’t have the answer, it recursively found the answer.

Troubleshooting DNS Issues

Let’s say you try to load a website in Google Chrome and it doesn’t work. But it works fine on your mobile device. This could be a DNS related issue.

The easiest and fastest way to test if you have a DNS problem, is to directly enter the IP address in the browser. Of course you will need to know the IP before hand so this isn’t super helpful.

The other option is to try using different DNS servers. For example, you can try Google’s DNS 8.8.8.8 or CloudFlare’s DNS 1.1.1.1.

If you’re using Mac, you can configure DNS servers under Network Preferences. You can also configure DNS settings on your router. If you’re on Windows or other OS, you can do a quick Google search to find OS specific instructions.

I hope this post gives you some insight about how DNS works. If you have any questions or thoughts, please leave them in the comments below. Thanks.

First Post – Perfection

This is the official first post on this blog. 2020 is almost here and I guess it is time for me to start blogging again. I have been trying to do this since July 2012 but failed to keep up every single time.

What’s different this time? Nothing much, except that I want to focus on the concept of “getting things out” and “shipping things” instead of trying to make them perfect.

I also want to focus on my real experiences instead of writing about something just because it is cool. It’s one of the mistakes I did before, where I found a cool topic, I read everything about it and then made blog posts on that. That works in the short run but gets boring quickly.

I have a basic idea of what I’ll be writing about and here’s a list of that:

  • Computer Science
  • Everything that I know and am learning currently in CS
  • My experience as Support Engineer and Team Lead working at Automattic
  • Productivity hacks
  • And more

Also, as the post title says, I’ll try to push things out and focus less on perfection. Writing something is much better than writing nothing.

So my goal is to avoid Perfection paralysis and produce more content (even if it isn’t on the level where I’d like it to be).

If you can relate to this and have any thoughts to share, please let me know in the comments below.

For now there isn’t any content on the site but feel free to bookmark it and check again later. Thanks!