Nginx reverse proxy to non-standard ssl port

httpsnginxreverse-proxyssl

I am having a terrible time getting this to work, here's my config file. When I navigate to 'sub.domain.com' I'm redirected to an https version of the URL so I know nginx is receiving the request, but the reverse proxy isn't loading 10.3.2.200:8443. When I load "https://sub.domain.com", Chrome tells me "ERR_CONNECTION_CLOSED". I'm using snippets from other answers on StackExchage + other online tutorials but with no success.

As a peculiarity, if I run a test and change 443 to 20205 in the second server block, then the reverse proxy works with 'https://sub.domain.com:20205' and successfully forwards to 10.3.2.200:8443.

## running on 10.3.2.205
upstream destsrv {        
    server 10.3.2.200:8443;
}
server {        
    listen 80 http2;
    listen [::]:80 http2;        
    server_name sub.domain.com;        
    return 301 https://$server_name$request_uri;
}
server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name sub.domain.com;
    ssl_certificate /etc/letsencrypt/certs/star_domain_com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/certs/star_domain_com/privkey.pem;
    location / {
        proxy_pass https://destsrv;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_http_version 1.1;
    }
}

This is a reverse proxy on a home server, I have ports 80 and 443 forwarded to my nginx server.

What's going on here?

Best Answer

@FedericoGalli Turns out my router was listening for connections on 443, so my redirect was never making it through to the web server. Once I stopped that, it started working.

Moral of the story: Don't just check your running web servers, make sure that your routing devices themselves aren't using certain ports.