LLI Wiki — My Digital Knowledge Base

PrivateBin on nginx and uWSGI: /run folder, Certbot and GoAccess

Memo: ownership, missing /run folder for uWSGI, Let's Encrypt certificate with Certbot and a real-time GoAccess report.

Operations memo for a PrivateBin instance served by nginx and uWSGI on Debian: folder ownership, missing /run directory, a Let's Encrypt certificate with Certbot and a real-time GoAccess report. The initial installation follows this guide (in French).

Application folder ownership

The privatebin system user must own the code and the data folder:

sudo chown -R privatebin:privatebin <install_dir>/privatebin
sudo chown -R privatebin:privatebin /var/lib/privatebin

uWSGI service no longer starts: missing /run directory

If the uWSGI configuration (/etc/uwsgi/privatebin.ini) puts its socket in /run/privatebin, that folder disappears at every reboot because /run is a temporary filesystem. The service then fails at startup (see journalctl -xeu <service>). Immediate fix:

sudo mkdir /run/privatebin
sudo chown privatebin:privatebin /run/privatebin
sudo systemctl restart <the application's uwsgi service>

To have the folder recreated at each boot, see this discussion: What's the best way to have uWSGI create a /run/uwsgi folder on reboot.

Let's Encrypt certificate with Certbot

sudo certbot --nginx --agree-tos --redirect --staple-ocsp --email admin@example.com -d privatebin.example.com
Option Purpose
--nginx Uses the nginx plugin: obtains the certificate and edits the site configuration
--agree-tos Accepts the terms of service without prompting
--redirect Adds the HTTP to HTTPS redirect
--staple-ocsp Enables OCSP stapling
--email Contact address for expiry notices
-d Domain name of the certificate

To remove a certificate manually (for example after a failed issuance), delete its three locations:

sudo rm -rf /etc/letsencrypt/live/privatebin.example.com/
sudo rm -rf /etc/letsencrypt/renewal/privatebin.example.com.conf
sudo rm -rf /etc/letsencrypt/archive/privatebin.example.com/

sudo certbot delete --cert-name privatebin.example.com does the same cleanly.

Real-time GoAccess report over HTTPS

GoAccess builds an HTML report from the nginx access log. With --real-time-html it also serves a WebSocket; on an HTTPS site it needs the certificate and key:

goaccess /var/log/nginx/access.log -o /var/www/goaccess/report.html --real-time-html \
  --ssl-cert=/etc/letsencrypt/live/goaccess.example.com/fullchain.pem \
  --ssl-key=/etc/letsencrypt/live/goaccess.example.com/privkey.pem

The ssl_certificate, ssl_certificate_key, ssl_trusted_certificate, ssl_stapling and include .../options-ssl-nginx.conf directives that Certbot adds to the nginx server block point to the same files in the live/ folder.

Mastodon LLIMastodon SocialFosstodon