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;

  ssl_certificate /etc/letsencrypt/live/;
  ssl_certificate_key /etc/letsencrypt/live/;

  location / {
    proxy_pass_header Server;

My config.php looks like this:

$CONFIG = array (
  'trusted_domains' => 
    array (
      0 => '',
      1 => '',
  'trusted_proxies' => 
    array (
      0 => '',

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