Smeltery
Get started

Deployment

v0.1

HTTPS: Caddy or nginx

The app listens on 127.0.0.1:8000; a reverse proxy on the same machine terminates HTTPS. The app compresses its responses itself and never buffers its two event streams (/_sparks/stream for Sparks push and the live dashboard, /_watchfire/api/events); both send a keep-alive every 15 seconds. The app also sends its own security headers (X-Content-Type-Options, Referrer-Policy, X-Frame-Options, Content-Security-Policy: frame-ancestors, and Strict-Transport-Security with HSTS_MAX_AGE; see The server), so the proxy needs no header settings of its own; neither configuration below adds any, and an nginx add_header for one of them would send it a second time.

Caddy gets and renews the certificate itself, sets X-Forwarded-For, -Proto and -Host, has no body-size limit by default and flushes event streams at once. /etc/caddy/Caddyfile:

text
app.example.com {
    reverse_proxy 127.0.0.1:8000
}
shell
sudo apt install caddy
sudo nano /etc/caddy/Caddyfile
sudo systemctl reload caddy

A write timeout in Caddy's global options (servers { timeouts { write 60s } }) ends each event stream at that limit; the browser's EventSource then reconnects. Leave write unset for the server that carries the app to keep streams open. When a client sends no Accept-Encoding, Caddy asks the app for gzip and decompresses the answer itself, so that client gets a weak ETag and no Content-Length; this is harmless, and transport http { compression off } inside reverse_proxy turns it off:

text
app.example.com {
    reverse_proxy 127.0.0.1:8000 {
        transport http {
            compression off
        }
    }
}

nginx with a Let's Encrypt certificate from certbot. /etc/nginx/sites-available/myapp:

nginx
server {
    listen 80;
    listen [::]:80;
    server_name app.example.com;

    # At least UPLOAD_MAX_BYTES (10 MiB by default); nginx's own default is 1 MiB.
    client_max_body_size 10m;

    location / {
        proxy_pass http://127.0.0.1:8000;
        proxy_http_version 1.1;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-Host $host;
    }

    # Server-sent events: passed on unbuffered.
    location ~ ^/(_sparks/stream|_watchfire/api/events) {
        proxy_pass http://127.0.0.1:8000;
        proxy_http_version 1.1;
        proxy_set_header Connection "";
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-Host $host;
        proxy_buffering off;
        proxy_cache off;
    }
}
shell
sudo apt install nginx certbot python3-certbot-nginx
sudo ln -s /etc/nginx/sites-available/myapp /etc/nginx/sites-enabled/myapp
sudo nginx -t && sudo systemctl reload nginx
sudo certbot --nginx -d app.example.com

certbot --nginx adds the listen 443 ssl lines and the redirect from HTTP to the server block, and renews the certificate with a systemd timer. The app's REQUEST_TIMEOUT (30 s) is below nginx's default 60 s proxy_read_timeout. proxy_read_timeout and send_timeout (both 60 s by default) limit the time between two reads or writes, not a whole response, so the 15-second keep-alives keep event streams open; a value under 15 s in the event-stream location would cut them.

Plesk. The app runs as above (binary, .env and folders in a directory of their own, the systemd unit, created as root over SSH); Plesk's nginx is the proxy. For the domain, turn on SSL/TLS with Let's Encrypt, open Apache & nginx Settings, turn off Proxy mode and put this into Additional nginx directives (Plesk's own configuration already has a location /, so these blocks use regular expressions, which nginx prefers over prefix locations, in the order written):

nginx
client_max_body_size 10m;

location ~ ^/(_sparks/stream|_watchfire/api/events) {
    proxy_pass http://127.0.0.1:8000;
    proxy_http_version 1.1;
    proxy_set_header Connection "";
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-Host $host;
    proxy_buffering off;
}

location ~ ^/ {
    proxy_pass http://127.0.0.1:8000;
    proxy_http_version 1.1;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-Host $host;
}

A Smeltery app is a long-running process with its own port. Hosting that offers only PHP or CGI, with no SSH access and no way to keep a process running, cannot run it.

↑↓ moveEnter openEsc close