mwild.co.uk

Setup recipe for blog.mwild.co.uk

The following recipe details how the blog at www.mwild.co.uk is set up on a FreeBSD 15 server.

Install and configure nginx

  1. Install nginx:

    # pkg install nginx
  2. Create the conf.d directory:

    # mkdir /usr/local/etc/nginx/conf.d

    /usr/local/etc/nginx/conf.d/www.mwild.co.uk.conf:

    server {
      listen 80;
      listen [::]:80;
      server_name mwild.co.uk;
      return 301 https://www.mwild.co.uk$request_uri;
    }
    
    server {
      listen 80;
      listen [::]:80;
      server_name www.mwild.co.uk;
    
      root /usr/local/www/www.mwild.co.uk;
      index index.html;
    
      location / {
        try_files $uri $uri/ =404;
      }
    
      location = /feed.xml {
        types { } default_type application/rss+xml;
        charset utf-8;
        charset_types application/rss+xml;
      }
    }
  3. Delete the default nginx server block and add the following to the end of the http block in /usr/local/etc/nginx/nginx.conf. Also enable gzip compression:

    gzip on;
    gzip_types application/rss+xml text/css application/javascript;
    include /usr/local/etc/nginx/conf.d/*.conf;

Create the webroot

# mkdir -p /usr/local/www/www.mwild.co.uk
# chown -R www:www /usr/local/www/www.mwild.co.uk

Enable and start nginx

# sysrc nginx_enable="YES"
# service nginx start

Enable TLS with Let’s Encrypt

  1. Install certbot:

    # pkg install security/py-certbot-nginx
  2. Obtain a certificate:

    # certbot --nginx -d www.mwild.co.uk -d mwild.co.uk
  3. Configure weekly renewal of the certificate by creating /etc/periodic.conf:

    weekly_certbot_enable="YES"

Configure firewall

  1. Edit /etc/pf.conf:

    ext_if = "vtnet0"
    tcp_services = "{ ssh, http, https }"
    
    block in all
    set skip on lo
    
    pass inet proto icmp all
    pass inet6 proto icmp6 all
    pass in on $ext_if proto tcp to port $tcp_services
    pass out on $ext_if from any to any keep state
  2. Verify the configuration:

    # pfctl -vnf /etc/pf.conf
  3. Enable the firewall:

    # sysrc pf_enable="YES"
    # service pf start