---

A blog entry about the blog

Every self-respecting blog must talk about blog, at least at some point. Finally this point came for this blog as well.

The reason for this is to share the admittedly hacky, fragile, and otherwise non-recommended configuration with the world, and attempt to trigger the wrath of all sorts of best practices people.

Historically, this site was running under lighttpd - when it appeared, nginx was less popular, and the lighttpd seemed like a better choice for this or that reason. lighttpd had also very cool options for inserting the headers and trailers into the file directory - so flexible, that I eventually made it a base for the "zero-code" blog. However, with time, it remained the only instance of lighttpd that I had dealt with, which obviously started to be inconvenient. So I moved to nginx. However, the default listing on nginx is rather basic - even if it perfectly does the job for normal uses, it was not good enough for mine.

It took a bit of time to figure out the way to crete a suitable nginx configuration, and finally it seems to do what I want - thus I decided that it would be a good enough reason to write a "blog entry".

The basic idea is that you encode the YYYY-MM-DD into the start of the directory name, and then goes the text of the title. This becomes a directory. The file HEADER.txt in the directory becomes the text of the blog entry. Conveniently, if I want to drop any other files there - it is trivially easy to do. The file listing also gives an artisanal "up" link. With a little bit of trickery, this allows to serve lynx-compatible text - though the directory names in the listing are truncated.

So, I decided to go a bit further and asked Claude.ai to make me a function to massage the listing upon document load, such that the browsers show nicer links. The results you can see here. Feel free to peruse view source. And here is the potentially interesting nginx configuration:

server {
       listen 80;
       listen [::]:80;

       server_name stdio.be;

       root /var/www/stdio.be;
       index index.html;

       location /HEADER.txt {
             internal;
	     alias /var/www/stdio.be/$request_uri/HEADER.txt;
	     error_page 404 = @missing_header_txt_404;
       }
       # do not output anything if header.txt is missing
       location @missing_header_txt_404 {
	       internal;
	       return 200 "";
       }

       location /FOOTER.txt {
             internal;
	     alias /var/www/stdio.be/$request_uri/FOOTER.txt;
	     error_page 404 = @missing_footer_txt_404;
       }
       # do not output anything if footer.txt is missing
       location @missing_footer_txt_404 {
	       internal;
	       return 200 "";
       }
       location / {
               try_files $uri $uri/ =404;
       }

       location /blog {
               try_files $uri $uri/ =404;
	       autoindex on;
               autoindex_localtime off;   # This is required for add_before_body to work

	       autoindex_format html;
	       ssi on;

	       sub_filter_types text/html;  # Only process HTML responses
	       sub_filter "<head><title>301 Moved Permanently</title></head>"
		       "<head><title>301 Moved Very Permanently</title></head>";

	       sub_filter "<body>" "
		       <body>
		       <!--#include file=\"/COMMON-HEADER.txt\" -->
		       <!--#include file=\"/HEADER.txt\" -->
		       ";
	       sub_filter "</body>" "
		       <!--#include file=\"/FOOTER.txt\" -->
		       <!--#include file=\"/COMMON-FOOTER.txt\" -->
		       </body>
		       ";
	       sub_filter "<title>Index of /blog/</title>" "<title>AY scribbles</title>";
	       # tweak the index of files in the end to use <h2> and be a bit more human
	       sub_filter "<h1>Index of /blog/</h1>" "";
	       sub_filter "<h1>Index of /blog/" "<h2>Files in ";
	       sub_filter "/</h1><hr><pre>" ":</h2><hr><pre>";
	       sub_filter "<head>" "<head><link rel='stylesheet' href='/stdio.css' type='text/css'><script src='/stdio.js'></script>";
	       sub_filter_once on;
       }
}

Files in 2024-11-27-A-blog-entry-about-the-blog:


../
HEADER.txt                                         27-Nov-2024 23:13                4231

(c) Andrew Yourtchenko