brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: nginx try_files serves index.html for deep links in a single-page app

Nginx
~/tips/tip-nginx-try-files-spa-fallback

try_files $uri $uri/ /index.html;

Falls back to one HTML file when the requested path does not exist on disk.

Reloading a page like /settings/profile gives a 404 when the frontend router lives in one index.html.

location / {
    try_files $uri $uri/ /index.html;
}

try_files checks the listed paths in order: a file, then a directory, then the last argument, which is an internal redirect to /index.html. The last item is not checked for existence, and it can also be a status like =404. If the same server block also handles API paths, give them their own location, because anything unmatched there returns the HTML page with status 200.

Further reading: ngx_http_core_module: try_files

Going deeper: 🛜 Guide: AdGuard Home + Tailscale (Secure Split-Horizon DNS)

More Nginx tips sudo certbot --nginx -d example.com -d www.example.com /data/nginx/custom/server_redirect.conf map $http_upgrade $connection_upgrade { proxy_intercept_errors on; proxy_redirect http://localhost:3000/ /app/; All Nginx tips (50) All topics

Link