Marcio Cunha

How to Configure Custom Error Pages and Hide the Web Server Version

Learn how to replace standard error pages with professional interfaces and remove web server signatures like Nginx and Apache to shield your application from targeted attacks.

Marcio Cunha4 min
Also available in:EspañolPortuguês
Summary
  • Standard error pages expose technological details that make life easier for attackers looking for known software vulnerabilities.
  • Hiding the Server header and version signature in Nginx or Apache drastically reduces the initial attack surface.
  • Errors 404, 502, and 504 require distinct handling to separate routing failures, microservice downtime, and request timeouts.
  • Maintaining the correct HTTP status code while displaying custom pages ensures search engine crawlers understand the real page status.
  • User experience improves significantly when an unexpected failure presents alternative navigation paths instead of raw technical screens.

Why Displaying Default Error Pages Is a Security Risk

When a visitor accesses a non-existent address or when the server suffers a sudden crash, the application usually displays generic messages generated by the infrastructure software itself. These basic screens reveal, without hesitation, the exact name of the web server and the precise version running behind the site. In practice, this means handing over a roadmap to cybercriminals who use these signatures to uncover known security flaws in that specific version and attempt to breach the system. Replacing these ugly pages with clean, professional interfaces is not just an aesthetic matter, but a fundamental layer of defense for any project on the internet.

Understanding Critical Codes: 404, 502, and 504 in Practice

To configure an efficient error route, we first need to understand what each number means in web technical jargon. The 404 code simply indicates that the typed address was not found on the server, which can happen due to a broken link or a typing mistake. Meanwhile, the 502 error represents a communication issue where the main server tried to talk to a helper program or supporting microservice and received no valid response. Finally, the 504 error points to a timeout, meaning the server took so long to process the task that it gave up waiting. Treating each of these scenarios separately prevents the user from getting lost without knowing if the error was in the link or if the entire system went down.

How to Hide Server Version Signatures in Nginx and Apache

The first practical step to secure your infrastructure is to silence the web server so it stops broadcasting details about its internal technology. In Nginx, a high-performance software widely used to deliver pages quickly, this is done by adjusting specific directives in the main configuration file. In practice, we disable version display and change the public signature to generic names or leave it completely blank. In Apache, the web's most traditional competing software, the process involves tweaking server signature and operating system token exposure directives. The goal of these changes is to prevent a simple network inspection tool from figuring out which software powers your business.

To apply this defense in Nginx, you must edit the global configuration file and add specific commands inside the main block. See the code snippet required to perform this change securely:

http {
server_tokens off;
more_set_headers 'Server: SecureServer';
}

If you use Apache as your main server, the procedure requires adjustments in the security configuration file to hide system details. Use the directives below to disable the display of versions and internal names:

ServerSignature Off
ServerTokens Prod

Configuring Custom Error Pages on the Web Server

Once the server is silent and secure against version exposure, the time comes to create friendly pages for when things go wrong. Instead of delivering unformatted text, we configure the server to redirect the visitor to a stylized HTML file featuring your brand's visual identity. It is crucial to ensure that the server maintains the correct HTTP status code when displaying this page, because if the site returns a success code for a page that does not exist, search engines might index the error incorrectly. Proper configuration links each error number to a specific physical file inside your project folder.

To configure these custom routes in Nginx, we use the error directive coupled with the corresponding file paths. The following example demonstrates how to map the most common errors to dedicated pages:

server {
listen 80;
server_name mydomain.com;

error_page 404 /404.html;
error_page 502 504 /500.html;

location = /404.html {
root /var/www/html;
internal;
}
}

Validating the Configuration and Testing Server Response

After saving the configuration files and restarting the web server services, the validation step ensures that everything is working as expected. In practice, we use command-line tools to simulate a request and inspect the HTTP response headers sent by the machine. The main goal of this verification is to confirm that the field revealing the software version has completely vanished or displays only generic text. Additionally, testing navigation on non-existent URLs confirms whether the stylized page loads quickly without breaking the layout or corrupting network status codes.

  1. Open your computer's terminal to interact directly with the test server.
  2. Run the request command to inspect the invisible details of the HTTP response:
    curl -I https://mydomain.com/non-existent-page
  3. Confirm that the version header has disappeared and that the returned numeric code matches the expected error type.

Final Considerations on Server Maintenance and Security

Setting up custom error pages and hiding the server version are practices that require ongoing attention throughout the application lifecycle. As new security updates are released for Nginx or Apache, configuration files must be reviewed to ensure no old directive is accidentally overwritten. Furthermore, maintaining a routine of periodic testing helps identify configuration flaws before a real visitor bumps into a broken error screen. Information security is built in layers, and closing these small structural gaps considerably raises the resilience of your entire digital ecosystem.