Https don't working

Nextcloud version (19.0.2):
Operating system and version (Docker linuxserver image):

The https is not working i have the error:

ERR_TOO_MANY_REDIRECTS

I specify that my nginx server is in a debian vm which is a router and passes all the network traffic

My nginx config

#NextCloud HTTP
server {
    if ($host = nextcloud.domainename.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    listen    80;
    server_name    nextcloud.domainename.com;
	return 301 https://$server_name$request_uri;

}

#NextCloud HTTPS
server {
    listen 443 ssl;
    server_name    nextcloud.domainename.com;
	access_log /var/log/nginx/nextcloud.access.log; 
	
    location / {
		include proxy_params;
        proxy_pass http://backend_nextcloud;
    }
	
    ssl_certificate /etc/letsencrypt/live/nextcloud..domainename.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/nextcloud.domainename.com/privkey.pem; # managed by Certbot
}