Reverse proxy keeps redirecting to Nextcloud server URL

I’m missing something simple and obvious. I hate to post for help, but I’ve been fighting with this for hours. I’m trying to run Nextcloud on a separate server behind a nginx reverse proxy. However, whenever I hit the proxy, the Nextcloud server sends a 302 + 307 response, and my browser’s URL is redirected to the Nextcloud server. How do prevent this and keep the browser URL as the proxy server?

I’ve also tried using Apache just for kicks, but no luck. Also, a reverse proxy to other servers works just fine, so Nextcloud is forcing a redirect for some reason.

Here’s my nginx config:

server {
  listen 443 ssl default_server;
  listen [::]:443 ssl default_server;

  server_name proxy.mydomain.com;
  ssl_certificate /etc/letsencrypt/live/proxy.mydomain.com/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/proxy.mydomain.com/privkey.pem;

  location / {
    proxy_pass_header Server;
    proxy_pass http://nextcloud.mydomain.com/;
  }
}

My config.php looks like this:

<?php
$CONFIG = array (
  'trusted_domains' => 
    array (
      0 => 'proxy.mydomain.com',
      1 => 'nextcloud.mydomain.com',
    ),
  'trusted_proxies' => 
    array (
      0 => 'proxy.mydomain.com',
    ),
);

Turns out it just required setting the overwritehost parameter in config.php. That’s fun.