Zero-Port Deployment & Nginx Setup
Deploy Staticraft in production using zero exposed application ports, Nginx static file serving, systemd service management, and atomic POSIX swaps.
1. Production Generator Mode (staticraft start)
In production, run `staticraft start`. The worker daemon runs in an isolated private environment without opening any public HTTP ports. It pulls data, renders HTML, and performs atomic file swaps into `.raft/`.
staticraft start
2. Atomic POSIX Swaps (rename(2))
Staticraft writes compiled HTML to staging temporary files before executing an atomic `rename(2)` system call to replace the target file in `.raft/`. This ensures web servers like Nginx never serve partially rendered files or encounter torn reads.
[Staging File] -> atomic rename(2) -> .raft/index.html
3. Nginx Production Configuration
Point Nginx directly to the `.raft/` output folder for maximum static delivery throughput:
server {
listen 80;
server_name staticraft.dev;
root /var/www/staticraft-website/.raft;
index index.html;
# Immutable caching for hashed assets
location ~* \.[a-f0-9]{8}\.(css|js|png|jpg)$ {
expires 1y;
add_header Cache-Control "public, immutable";
}
# Fallback static page routing
location / {
try_files $uri $uri/ /index.html =404;
}
# Custom 404 page handling
error_page 404 /404.html;
}
4. Systemd Background Worker Service
Create a systemd unit file to keep `staticraft start` running as a background service on Linux servers:
# /etc/systemd/system/staticraft.service
[Unit]
Description=Staticraft Background Site Engine
After=network.target
[Service]
Type=simple
User=deploy
WorkingDirectory=/var/www/staticraft-website
ExecStart=/usr/local/bin/staticraft start
Restart=always
[Install]
WantedBy=multi-user.target