How do I configure nginx for proxy_pass and ssl redirect? - Stack Overflow

时间: 2025-01-06 admin 业界

I'm using this guide to set up nginx to serve a dash application, but unable to connect to the webserver with https. Here's my nginx.conf file:

events {
    worker_connections  1024;
}
http {
    server_tokens off;
    charset utf-8;

    # always redirect to https
    server {
        listen 80 default_server;

        server_name _;

        return 301 https://$host$request_uri;
    }

    server {
        listen 443 ssl http2;
        # use the certificates
        ssl_certificate     /etc/letsencrypt/live/{my_domain}/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/{my_domain}/privkey.pem;
        server_name {my_domain};
        root /var/www/html;
        index index.php index.html index.htm;


        location / {
            proxy_pass http://my-dash-app:5000/;
        }

        location ~ /.well-known/acme-challenge/ {
            root /var/www/certbot;
        }
    }
}

Where {my_domain} is my actual domain name. fullchain.pem and privkey.pem files appear to have been generated, and I can use https://localhost to connect on my LAN, but I get a message in the browser saying the site is not secure and have to add an exception before it will load.

What am I doing wrong here?