NGiИX reverse proxy support

I failed to find a simple explanation on how to access the UI remotely through nginx (NGiИX). Here is what I tried

server {
    server_name sub.example.tld;

    auth_basic 'PROVE IDENTITY';
    auth_basic_user_file /etc/nginx/sub.example.tld/.htpasswd;

    listen [::]:443 ssl; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/sub.example.tld/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/sub.example.tld/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

    rewrite ^/$ /webui/ last;

    location / {
        proxy_pass http://localhost:8080;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }

    location ~ ^/(webui|api)/ {
        proxy_pass http://localhost:5001;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

server {
    if ($host = sub.example.tld) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    listen 80;
    listen [::]:80;
    server_name sub.example.tld;
    return 404; # managed by Certbot
}

TLS and Basic Auth work. I get redirected to https://sub.example.tld/ipfs/<some blurb>/#/welcome which displays the UI skeleton. But then nothing else loads. The only thing that triggers a change in the UI is clicking the Settings tab. In devtools (firefox) I see a bunch of 404 GET to URLs looking like https://sub.example.tld/ipfs/<some blurb>/locales/en-US/app.json and also 403 POST https://sub.example.tld/api/v0/stats/bw and http://127.0.0.1:5001/api/v0/stats/bw.

Originally asked at https://github.com/ipfs-shipyard/ipfs-webui/issues/1676