Hostwinds Blog

Search results for:


Troubleshooting HTTP 5xx and 4xx Status Errors Featured Image

Troubleshooting HTTP 5xx and 4xx Status Errors

by: Hostwinds Team  /  June 6, 2024


Whether browsing the internet or running it, we've all run across an HTTP status error at one point or another. These inevitable peccadillos can be frustrating for users and, if not addressed, detrimental to a website's credibility.

HTTP errors can occur on either the client (4xx) or server (5xx) side. This guide will go over common errors from both perspectives and provide a few tips on how you, the site owner, can remedy each issue.

5xx Errors (Server-Side)

Server-side errors happen when there's an issue with the server that's hosting the website. Unless you have root access, these types of errors may be out of your (the website owner) control and require the attention of the web hosting provider.

The most common server-side errors are:

  • 500 Internal Server Error
  • 502 Bad Gateway
  • 503 Service Unavailable
  • 504 Gateway Timeout

500 Internal Server Error

The 500 error occurs when there's an issue with the server, but the server can't provide any additional information about the issue. The error message usually says something like "500 Internal Server Error" or "Internal Server Error."

Common causes: Coding errors or problems with the server's configuration.

How to Fix a 500 Internal Server Error

Check the error log

The error log is a useful tool that can provide more information about the error. You can access the error log through your hosting control panel or by connecting to the server via FTP. Look for any error messages or warnings that may indicate the root cause of the error.

Disable plugins or scripts

If the error occurs after installing or updating a plugin or script, try disabling it to see if that resolves the issue. If the website works fine after disabling the plugin or script, it may be outdated or incompatible with your website's server configuration.

Increase server resources

If your website is experiencing a spike in traffic or using more resources than your server can handle, you may need to increase your server resources. This can be done by upgrading your hosting plan or optimizing your website's code and database to reduce the load on the server.

Check file permissions

Incorrect file permissions can also cause a 500 internal server error. Make sure that your files have the correct permissions and that your server user has permission to access the files.

Reupload core files

If the error persists, try reuploading the core files of your website. Sometimes, files can become corrupted during the upload process or due to other issues, causing errors. Reuploading the files may resolve the issue.

502 Bad Gateway

This error occurs when the server acting as a gateway or proxy receives an invalid response from the upstream server. This error message usually says "502 Bad Gateway" or "Error 502."

Common causes: Upstream server issues and network connectivity problems.

How to Fix a 502 Bad Gateway

Check the upstream server

Check the upstream server (the server providing the data) to ensure that it is running correctly. This can be done by contacting the server administrator or checking the server status page.

Disable CDN or firewall

Sometimes, these services can interfere with the connection between the server and client. If you are using a CDN (content delivery network) or firewall, try disabling it temporarily to see if that resolves the issue.

Check server logs

Server logs can provide more information about the cause of the error. Check the server logs for any error messages or warnings that may help diagnose the issue.

Restart server or services

Sometimes, simply restarting the server or services can resolve the issue. This can be done through your hosting control panel or by contacting your web hosting provider or IT department.

503 Service Unavailable

This error occurs when the server is temporarily unavailable to handle requests. This error message usually says "503 Service Unavailable" or "Service Unavailable."

Common causes: Server overload or server maintenance.

How to Fix a 503 Service Unavailable

Check server status

Check the server status to ensure that it is running correctly. This can be done by contacting the server administrator or checking the server status page.

Check maintenance mode

If your website is undergoing maintenance or updates, check if the maintenance mode is enabled. Disable maintenance mode if it is enabled, and see if that resolves the issue.

Check server resources

If your website is experiencing a spike in traffic or using more resources than your server can handle, you may need to increase your server resources. This can be done by upgrading your hosting plan or optimizing your website's code and database to reduce the load on the server.

Check DNS settings

Incorrect DNS (domain name system) settings can cause a 503 error. Make sure that your DNS settings are correct and that your domain is pointing to the correct server.

Restart server or services

Sometimes, simply restarting the server or services can resolve the issue. This can be done through your hosting control panel or by contacting your web hosting provider or IT department.

504 Gateway Timeout

A 504 Gateway Timeout error occurs when a server acting as a gateway or proxy doesn't receive a timely response from an upstream server it needs to access to complete the request.

Common causes: Slow upstream server or network connection issues

How to Fix 504 Gateway Timeout

Increase timeout settings

Adjust the timeout parameters in your server or proxy configuration to allow more time for the upstream server to respond.

Optimize upstream server

Improve the performance of the backend server (e.g., database, API) to handle requests faster and prevent timeouts.

Fix network issues

Check for and resolve any network problems between your server and the upstream server, such as slow connections or firewall issues.

Load balance traffic

Consider implementing DNS load balancing to distribute requests across multiple upstream servers. This will help prevent any single server from becoming overwhelmed.

4xx Errors (Client-Side)

4xx HTTP status codes indicate client-side errors, meaning the issue lies with the request made by the client, typically through a web browser or API client. These errors suggest that the server could not fulfill the client request (e.g. accessing a webpage) because it was invalid or malformed.

Usually it's the client (user) who needs to remedy the error, though the issue could also be caused by the site owner (e.g. improper URL redirection).

The most common 4xx errors are:

  • 400 Bad Request
  • 401 Unauthorized Request
  • 403 Forbidden
  • 404 Not Found

400 Bad Request

This error occurs when the server cannot understand the request sent by the client (user). This error message usually says "400 Bad Request" or "Bad Request."

Common causes: incorrect URL formatting or invalid input from client.

How to Fix a 400 Error

Check request headers

Request headers provide additional information about the request being sent to the server. Check the request headers to ensure that they are correctly formatted and do not contain any invalid data.

Validate and sanitize input parameters

Ensure your server correctly handles and validates all incoming data, rejecting or escaping any malformed or potentially harmful inputs.

Request parsing code bugs

Review and fix any issues in your server's code that handles parsing of incoming HTTP requests, as bugs here often lead to 400 errors.

Special characters in URLs

Make sure your server properly handles special characters (like ?, &, #) in URLs, as incorrect handling can make requests appear malformed.

Check rewrite rules

Review .htaccess or server configuration files for any rewrite rules that might be incorrectly modifying incoming requests.

401 Unauthorized Request

A 401 error code indicates that the request has not been applied because it lacks valid authentication credentials for the target resource. Simply put, it means the user trying to access a particular resource on the server doesn't have the necessary permissions or credentials.

Common causes: Missing/invalid authentication credentials or unsupported authentication method

How to Fix a 401 Error

Check authentication Credentials

Ensure that the user trying to access the resource has the correct username and password. If the resource is password-protected, incorrect credentials will result in a 401 error.

Review permissions

Verify that the user has the appropriate permissions to access the requested resource. Check the file or directory permissions on the server to make sure they allow the intended access.

Review Token Expiry (If Using Token-based Authentication)

If you're using token-based authentication, check whether the authentication token has expired. Refresh the token or generate a new one if needed.

Check server Logs

Server logs can provide insights into what specifically went wrong during the authentication process.

Check SSL Configuration

Ensure that the SSL certificate is valid and configured correctly.

Firewall or IP Blocking

Check if there's a firewall or security system in place that might be blocking the user's IP address. Whitelist the IP if necessary.

Web Server Configuration

Inspect the configuration of your web server (e.g., Apache, Nginx) to ensure that it is correctly set up for authentication.

403 Forbidden

A 403 Forbidden error occurs when the server understands the client's request but refuses to authorize it, typically because the client lacks the necessary permissions to access the requested resource.

Common causes: Client lacks permissions to access specific resource or server access restrictions

How to Fix 403 Error

Review file/directory permissions

Ensure the web server has the correct read and execute permissions for the requested files and directories.

Check user roles in CMS/database

Verify that the user's account in your content management system or database has the appropriate access rights for the requested content.

Inspect .htaccess rules

Look for overly restrictive directives in your .htaccess file that might be blocking access to certain files or directories.

Examine firewall/security plugin settings

Check if your firewall or security plugins are mistakenly flagging legitimate requests as threats and blocking access.

404 Not Found

Probably the most common of 4xx status errors, the 404 error occurs when the requested page or resource cannot be found on the server. This error message usually says "404 Not Found" or "Page Not Found."

Common causes: Broken links, deleted pages or incorrect server configuration.

How to Fix a 404 Error

Check for broken links

If the 404 error is occurring on a specific page, check for broken links on that page. Broken links can cause a 404 error when clicked on, even if the URL is correct. Use a broken link checker tool to identify and fix any broken links on your website.

Review server logs

Server logs can provide more information about the cause of the error. Check the server logs for any error messages or warnings that may help diagnose the issue.

Create custom 404 page

If the requested page does not exist, create a custom 404 error page that provides useful information and a search bar to help visitors find the content they are looking for. This can improve the user experience and reduce the number of visitors who leave the website due to a 404 error.

Redirect to a similar page

If the requested page no longer exists, redirect visitors to a similar page on your website using a 301 redirect. This will help preserve the SEO value of the old page and provide a better user experience.

Written by Hostwinds Team  /  June 6, 2024