Running Plainpad Behind Nginx With HTTPS

Running Plainpad Behind Nginx With HTTPS

Plainpad runs on any PHP-capable web server. Nginx with PHP-FPM is the common choice on a small VPS: it is light, it is well documented, and it does not need much tuning for an app this size.

Here is a configuration that works, and the reasoning behind each part.

The server block

server {
    listen 80;
    server_name notes.example.com;
    root /var/www/plainpad/public;
    index index.html;

    client_max_body_size 8m;

    location / {
        try_files $uri $uri/ /api.php?$query_string;
    }

    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_pass unix:/run/php/php8.3-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

    # Nothing outside the document root should ever be served.
    location ~ /\. {
        deny all;
    }
}

The try_files line is the one that matters: it sends anything that is not a real file to api.php, which is how the API routing works. The root points at public/ so the .env file and the rest of the app stay outside the web root. Get this wrong and every page except the homepage returns a 404.

TLS, free and automatic

sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d notes.example.com

Certbot edits the server block, adds the redirect from port 80, and installs a renewal timer. Check that the timer is actually running:

systemctl list-timers | grep certbot

A certificate that expires because nobody checked the renewal is a classic self-hosting failure, and it always happens on a Sunday.

Headers worth adding

Inside the TLS server block:

add_header Strict-Transport-Security "max-age=31536000" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "same-origin" always;
add_header X-Frame-Options "DENY" always;

Strict-Transport-Security tells browsers never to try plain HTTP for this host again. Only add it once HTTPS definitely works - it is sticky, and undoing it in every visitor’s browser is not possible.

Two checks before you call it done

curl -sI https://notes.example.com | head -1
curl -sI http://notes.example.com | head -2

The first should return 200. The second should return a 301 to the HTTPS URL. If either misbehaves, fix it now rather than discovering it from a phone on a train.

Keep it boring

There is no benefit in tuning worker counts or buffer sizes for a personal notes instance. Plainpad is a small PHP application serving a handful of requests a minute at most. The default Nginx and PHP-FPM settings are already generous. Spend the saved time on backups instead.

Services

Want a hand with Plainpad?

We can host it for you, help you fix a problem, put your brand on it, build something new or move your notes over.

See our services