Error handling is one of the important parts when running a server. The application running inside the server provides the necessary services to the client but it is the responsibility of the server to serve custom pages for errors. In this article we will see how we can configure custom error page 404 for Apache web server along with Tomcat.
- Create a 404 error page as
<html>
<head> Hello This a 404 Error page </head>
<body bgcolor=”green”>
</h3> this is green and 404 </h3>
</body>
</html>
Copy the file to /var/www/webroot/ROOT/ location
- Once the file is created, configure Apache Configuration file as
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot /var/www/webroot/ROOT/
ErrorDocument 404 /404.html
ServerName dummy-host.example.com
ErrorLog logs/dummy-host.example.com1-error_log
CustomLog logs/dummy-host.example.com1-access_log common
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
Options +Indexes
</Proxy>
ProxyPass /application1 http://localhost:8080/myApp/
ProxyPass /application2 http://localhost:8080/Sample-app/test.html
ProxyPassReverse /application1/ http://localhost:8080/myApp/
ProxyPassReverse /application2/ http://localhost:8080/Sample-app/test.html
</VirtualHost>
All we need to do is add an ErrorDocument entry to our http.conf file. On the ErrorDocument line, we specify the error code, which in this case is a 404. After that, we can specify either a text message or the page to display and then file to be displayed ( 404.html ). Restart the Apache server.
Now once we access a different path, we see the 404 error page as,
Recent Comments