Le Blog Utux

HTTP 200 GET /

OpenBSD: get rid of Comic sans ms in httpd error messages

Rédigé par uTux Aucun commentaire

I have been playing with OpenBSD and httpd lately. It's a really simple and fun webserver to use, despite suffering huge limitations, but I quickly stumble across this horror:

No joke. httpd will serve all errors messages with the infamous Comic sans ms font. It's probably a troll from the maintainers, at least I hope so. Comic sans ms sucks, I don't want that on my server. Fortunately, there is a simple way to disable it.

Add this line into your /etc/httpd.conf:

errdocs "/errdocs"

Then create the file /var/www/errdocs/err.html with the following content:

                                                                                                           
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>$RESPONSE_CODE $HTTP_ERROR</title>
<style type="text/css"><!--
body { background-color: white; color: black; }
hr { border: 0; border-bottom: 1px dashed; }
@media (prefers-color-scheme: dark) {
body { background-color: #1E1F21; color: #EEEFF1; }
a { color: #BAD7FF; }
}
--></style>
</head>
<body>
<h1>$RESPONSE_CODE $HTTP_ERROR</h1>
<hr>
<address>$SERVER_SOFTWARE</address>
</body>
</html>

Then restart httpd:

rcctl restart httpd

Explanation: httpd manage says:


A custom error document may contain the following macros that will be expanded at runtime:

$HTTP_ERROR
    The error message text.
$RESPONSE_CODE
    The 3-digit HTTP response code sent to the client.
$SERVER_SOFTWARE
    The server software name of httpd(8).

So I just took the source code of a 404 error page, removed the Comic sans ms part in the CSS and replaced the values (error code, message, server identity) by the proper variables. Now all errors messages should be generated with this new template, with a fallback font.

Écrire un commentaire

Quelle est le troisième caractère du mot ry2l61 ?