The Personal Website of Jeremy Boles

Nginx

A venerable and reliable web server.

Installation

Worth putting a firewall in front of anything on the internet first.

sudo apt install ufw
sudo ufw limit SSH
sudo ufw allow out 123/udp   # NTP
sudo ufw allow out DNS
sudo ufw enable

Then Nginx itself.

sudo apt install nginx
sudo ufw allow http
sudo ufw allow https
sudo systemctl enable --now nginx

I give myself write access to the web root rather than reaching for sudo every time:

sudo chgrp -R www-data /var/www
sudo chmod -R 774 /var/www
sudo chmod g+s /var/www
sudo adduser $(whoami) www-data

Create a Website

mkdir /var/www/example.com
vim /var/www/example.com/index.html
server {
        listen  80;
        listen  [::]:80;

        charset utf-8;

        root /var/www/example.com;
        index index.html;

        server_name example.com www.example.com;
}

Serving Paths Without the .html Extension

server {
        [...]
        location / {
            default_type "text/html";
            try_files $uri $uri.html $uri/index.html index.html $uri/ =404;
        }
        [...]
}

Serving Pre-Compressed Files

Debian packages a Brotli module. It does not package one for zstd, so zstd_static needs a module built by hand or dropping.

sudo apt install libnginx-mod-http-brotli-static
server {
        [...]
        brotli_static   on;
        gzip_static     on;
        [...]
}

Logging

I keep the logs for every site on a server in one file and read them with GoAccess.

log_format vcombined '$host:$server_port '
                     '$remote_addr - $remote_user [$time_local] '
                     '"$request" $status $body_bytes_sent '
                     '"$http_referer" "$http_user_agent"';
access_log /var/log/nginx/access.log vcombined;
goaccess --log-format=VCOMBINED --agent-list /var/log/nginx/access.log

And logrotate to keep the file from eating the disk.

sudo apt install logrotate