reverse proxy for Shiny app with authorization by polished package

,

I have created a Shiny App that implements user authentication with the Polished package. I am struggling to get this app to be able to connect to HTTPS via Nginx reverse proxy.
I am trying to set up a proxy from “https://mydomain” to “http://localhost:3838”. If I access “http://localhost:3838” I get the sign in page, but if I access “https://mydomain” it does not redirect me to the sign in page.
Can you please tell me how I should modify this Nginx setting?

server{
        root /var/www/html;
        index index.html index.htm index.nginx-debian.html;
        server_name mydomain;
        location / {
                proxy_pass http://127.0.0.1:3838;
                proxy_redirect / $scheme://$http_host/;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Forwarded-Proto $scheme;
                try_files $uri $uri/ =404;
        }
        listen 443 ssl; # managed by Certbot
        ssl_certificate /etc/letsencrypt/live/mydomain/fullchain.pem; # managed by>    
        ssl_certificate_key /etc/letsencrypt/live/mydomain/privkey.pem; # managed >    
        include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
        ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
    if ($host = mydomain) {
        return 301 https://$host$request_uri;
    } # managed by Certbot
        listen 80;
        server_name mydomain;
    return 404; # managed by Certbot
}