Problems setting up trusted domains for nginx reverse proxy

I am running nextcloud in a docker container, and I use nginx to redirect all the traffic from my subdomain ‘’ to the container that is listening at localhost:8081. My trusted domains array in the config looks like this:

'trusted_domains' => 
  array (
    0 => 'localhost:8081',
    1 => '',
  'trusted_proxies' =>
  array (
    0 => 'localhost',
    1 => '',
    2 => '',

This works, but some images will be broken since nextcloud links them using the localhost:8081 address, because to nextcloud it looks as if the client was requesting the page from localhost (because nginx resides on localhost). If I forward the host address with nginx by putting


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

into the nginx config for the site, then nextcloud will show an “Access through untrusted domain” error when I access the site through “”. Anyone have any suggestion on how to debug this further? Or a guide for setting nginx up as a reverse proxy with nextcloud?

P.S.: Why does nextcloud not tell me WHAT untrusted domain I am supposedly accessing it from? That would probably give me a huge hint on what is wrong. I checked the nextcloud log but couldn’t find anything on that.