Unable to forward real IP to Nextcloud container

I tried multiple methods and none of which seems to forward the real request IP to Nextcloud. I am running it via docker-compose, with a database and nginx reverse proxy all linked up. The nginx proxy is doing the ssl and redirect http requests to https. In my nginx config, it has the following.

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

    location / {
        proxy_pass http://nextcloud;
        proxy_buffering off;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Host $host;
        access_log off;
    }
}

I can see in the logs of nginx container that it is able to log the correct client request IP addresses. However, tailing the logs for Nextcloud, it only sees the IP for the nginx proxy. I tried rebuilding the image with remoteip and rpaf apache2 modules. Neither of which seems to work at all. In my config.php I also have the following lines added.

  'trusted_proxies' => ['proxy'],
  'trusted_domains' =>
  array (
    'nextcloud',
    'nextcloud.example.com',
  ),
  'overwrite.cli.url' => 'https://nextcloud.example.com',
  'overwriteprotocol' => 'https',

The hostname for nginx proxy is “proxy” and is resolvable in the Nextcloud container. I appreciate any clues on what I’m doing wrong.

I managed to get the fpm version working.