'Nginx error: *1 peer closed connection in SSL handshake

I have an asp.net app in docker container. I used certbot to set https.

Error:

*8 peer closed connection in SSL handshake (104: Connection reset by peer) while SSL handshaking to upstream, client: 220.152.160.127, server: api.domain.com, request: "GET / HTTP/1.1", upstream: "https://127.0.0.1:7443/", host: "api.example.org"

Docker ports binding:

7080 -> 80

7443 -> 443

Nginx config:

upstream api{
    server 127.0.0.1:7443;
}

server {
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/api.example.org/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/api.example.org/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
    
    server_name api.example.org;
    location / {
        proxy_ssl_server_name on;
        proxy_pass $scheme://api;
    }
}

server{
    if ($host = api.example.org) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    listen 80;
    server_name api.example.org;
    return 404; # managed by Certbot


}

I have some other containers where this config works fine.

Full nginx config:

Config

App Program.cs file

Redirect in app set to 7443



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source