How to use multiple ports on the same server for a single domain using nginx and SSL

I am using Godaddy as my domain registrar and created a <subdomain_name> which is linked to my servers IP address on Digital Ocean. I am also using Let’s encrypt to get SSL certificates and nginx as reverse proxy. Below is my nginx conf. file that I am using:

server {
        listen 443 http2 ssl;
        server_name <subdomain_name>;

        #Logging
        access_log /var/log/nginx/<subdomain_name>.access.log;
        error_log /var/log/nginx/<subdomain_name>.error.log;


        location /.well-known/acme-challenge/ {
                root /var/www/html/test; # Temp for generating letsencrypt
                default_type text/plain;
        }

        location / {
                proxy_set_header Host $host:$server_port;
                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;

                #Fix the “It appears that your reverse proxy set up is broken” error.

                proxy_pass http://127.0.0.1:3001;
                proxy_read_timeout 90;
                proxy_redirect http://127.0.0.1:3001 http://<subdomain_name>/;

                #Required for new HTTP-based CLI

                proxy_http_version 1.1;
                proxy_request_buffering off;
        }

        # SSL configuration
        ssl_certificate /etc/letsencrypt/live/<subdomain_name>/fullchain.pem; # managed by Certbot
        ssl_certificate_key /etc/letsencrypt/live/<subdomain_name>/privkey.pem; # managed by Certbot
        include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
        ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

server {
        if ($host = <subdomain_name>) {
                return 301 https://$host$request_uri;
        } # managed by Certbot

        listen 80;
        server_name <subdomain_name>;
        return 404; # managed by Certbot
}

Setup:

I am running multiple applications that are listening on different ports with some applications being dependent on each other.

Example:

http://<subdomain_name>:3001 -> being a nginx application angular frontend application
http://<subdomain_name>:3002 -> an API that provides http://<subdomain_name>:3001 with the necessary data
http://<subdomain_name>:3003 -> another service

Problem:

When I run the domains without ssl using just plain http like http://<subdomain_name>:3001, http://<subdomain_name>:3002, http://<subdomain_name>:3003 then they work fine.
However when I try to run it in https, then the following cant be accessed:

https://<subdomain_name>:3002, https://<subdomain_name>:3003

The browser says:

This website cannot provide a secure connection <subdomain_name> has sent an invalid response.
ERR_SSL_PROTOCOL_ERROR

Only https://<subdomain_name>:3001 works, as it is being redirected because that is what I indicated in my nginx.conf file. However I do get a console error that says

POST https://<subdomain_name>:3002/graphql net::ERR_SSL_PROTOCOL_ERROR

The problem is that https://<subdomain_name>:3002 throws an error that it is not able to supply the data because it cant make a post request due to it not being a secure ssl connection.

I played around with the nginx config by adding different server blocks for the different services but I cant get it to work.

I want that the following will work with https as well:

http://<subdomain_name>:3001    
http://<subdomain_name>:3002
http://<subdomain_name>:3003

Also, I want that service https://<subdomain_name>:3002 is able to provide data to https://<subdomain_name>:3001 by getting rid of this error.

POST https://<subdomain_name>:3002/graphql net::ERR_SSL_PROTOCOL_ERROR

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật