Skip to content

Serve ANSI, ASCII & BBS art

Below is a barebones configuration to serve plain text files using Nginx.

The location block applies the configuration only to files using the path http://example.com/ansi.

The served textfiles are in /var/www/example.com/html.

nginx.conf
server {
    listen 80;
    root /var/www/example.com/html;

    location /ansi {
        charset "ISO-8859-1";
        add_header Content-Disposition "inline";
        add_header X-Content-Type-Options "nosniff";
        types {
            text/plain asc ans txt;
        }
    }
}

Types
location /ansi {
    types {
        text/plain asc ans txt;
    }
}

The types block further filter files to those utilising an .asc .ans or .txt file extension.


Charset
location /ansi {
    charset "ISO-8859-1";
}

The charset "ISO-8859-1" directive combined with the types { text/plain } block adds a Content-Type:text/plain; charset=ISO-8859-1 response header.

It tells the browser to treat the file as plain text encoded as ISO-8859-1, a legacy character set RetroTxt can understand. You cannot use CP-437 or other DOS code pages as they are not valid browser encodings.


Content disposition
location /ansi {
    add_header Content-Disposition "inline";
}

The add_header Content-Disposition "inline"; directive adds a Content-Disposition:inline response header that tells the browser to display the content in a tab.


No sniff
location /ansi {
    add_header X-Content-Type-Options "nosniff";
}

The add_header X-Content-Type-Options "nosniff"; directive adds the X-Content-Type-Options:nosniff response header to tell browsers not to sniff the content.

MIME sniffing often inaccurately treats ANSI and other encoded text as binary files browsers download. Unfortunately, Firefox ignores this header request.

Chrome network console headers result

Response headers