HTTPS with a reverse proxy
Put nginx or Caddy in front of the API for HTTPS and a public address.
The built-in server speaks plain HTTP. Anything that leaves a private network should go through a reverse proxy that adds HTTPS. Keep the API on 127.0.0.1 so only the proxy can reach it.
Settings in webapi.yml:
enabled: true
host: 127.0.0.1
port: 8765
base-path: /v1
public-url: https://api.example.com
trust-forwarded-for: truetrust-forwarded-for: true makes the rate limits follow the real client address. It only trusts the header when the connection comes from the same machine, so a client cannot fake it.
nginx
server {
listen 443 ssl http2;
server_name api.example.com;
ssl_certificate /etc/letsencrypt/live/api.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/api.example.com/privkey.pem;
client_max_body_size 300k;
location /v1/ {
proxy_pass http://127.0.0.1:8765;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_read_timeout 40s;
proxy_connect_timeout 3s;
}
}$remote_addr replaces any X-Forwarded-For the client sent, which is what you want when nginx is the only proxy. Reload with sudo nginx -t && sudo systemctl reload nginx. Then:
curl -H "Authorization: Bearer $MD_KEY" https://api.example.com/v1/statusCaddy
api.example.com {
request_body {
max_size 300KB
}
reverse_proxy /v1/* 127.0.0.1:8765
}Caddy gets and renews the certificate itself. It sets X-Forwarded-For by default.
Limit who can connect
Allow only your own addresses in nginx:
location /v1/ {
allow 203.0.113.10;
allow 198.51.100.0/24;
deny all;
proxy_pass http://127.0.0.1:8765;
proxy_set_header X-Forwarded-For $remote_addr;
}Or keep the API private and reach it through an SSH tunnel:
ssh -N -L 8765:127.0.0.1:8765 user@your-server
curl -H "Authorization: Bearer $MD_KEY" http://127.0.0.1:8765/v1/statusCalling the API from a web page
A browser only lets a page call the API when cors-origin names the page's origin:
cors-origin: https://panel.example.comconst res = await fetch('https://api.example.com/v1/status', {
headers: { Authorization: `Bearer ${key}` },
});Do not put an admin or write key in a public web page. Anyone who opens the page can read it. Call the API from your own backend for those, and give a public page a read key at most.
Pterodactyl
If MineDuels runs in a Pterodactyl container, 127.0.0.1 inside the container is not the host. Either:
- run the proxy on the host and set
host: 0.0.0.0with the port allocated to the server, then allow only the proxy's address in the host firewall, or - use the allocation directly and
host: 0.0.0.0, with the allow-list above on the node's firewall.
Check with /md web url that the printed address matches what you use.