English
Topic 23. An Ubuntu virtual server: firewall, PostgreSQL, systemd, Nginx and HTTPS
Goal: prepare a virtual server for Chatex — an Ubuntu 26.04 droplet reachable only over SSH, HTTP and HTTPS, a PostgreSQL database with its own role, a service user with exactly one writable folder, a settings file outside the repository, a hardened systemd service and Nginx as a reverse proxy with WebSocket support, security headers and a free HTTPS certificate.
Where we are
The tested application now needs a home. This topic builds every part of the production machine except the application itself, which topic 24 delivers (Fig. 23.1).
Fig. 23.1. The production server
- Starting point: topic 22 — every push to
devpasses CI, andmainis protected. - At the end of the topic the server is ready for its first release: the firewall is active, the database and the settings exist, the service
chatex-apiis installed and enabled, andhttps://<your domain>/healthanswers502 Bad Gatewaythrough Nginx with a valid certificate — Nginx works, and only the API is still missing.
You need a server and a domain
This topic costs a little money: a virtual server with 1–2 GB of memory (a DigitalOcean droplet, as in the reference, or a comparable machine with Ubuntu 26.04 from any provider) and a domain name or a subdomain of a domain you own. HTTPS is not optional: the refresh cookie of topic 13 is Secure, so without HTTPS nobody could stay signed in. Delete the droplet when the course is over if you do not want to keep the site.
Steps
- The droplet — one machine for everything · an SSH key and the droplet · a DNS record · the packages · the firewall · a copy of the repository
- User, folders, database and settings — the service user · the folders · PostgreSQL · the settings file
- A hardened systemd service — why systemd · the unit file · the sandbox, directive by directive · installing and checking the service
- Nginx and HTTPS — why a reverse proxy · security headers · the site · installing the site · a certificate with certbot
- Checkpoint — what must work, self-check questions and exercises
Materials
- Course slides, part 6, Ubuntu server (slides "Deployment topology", "Setting up the server", "Files on the server", "A hardened systemd service", "Nginx as reverse proxy", "TLS and security headers")
Deploy/:chatex.env.example,chatex-api.service,chatex.conf,chatex-security-headers.confDocs/Deployment.md– the reference for every server command of this topic- systemd.exec (the sandboxing options), Nginx documentation, Certbot