Nginx 反向代理 SSL 错误

Nginx 反向代理 SSL 错误

因此我的 Nginx 反向代理设置如下。

    listen 80;
    server_name mydomain.net;
    return 301 https://mydomain.net$request_uri;
    }
server {
    listen 443;
    server_name mydomain.net;

    ssl_certificate           /etc/letsencrypt/live/mydomain.net/fullchain.pem;
    ssl_certificate_key       /etc/letsencrypt/live/mydomain.net/privkey.pem;

    location / {
       proxy_pass http://myip:myport;
    }
}


But when I try to connect to my website it says "This site can't provide a secure connection, ERR_SSL_PROTOCOL_ERROR. Did I misconfigure SSL?

答案1

您应该将 listen 指令更改为 listenSSL协议listen 80;说要监听http端口 80 上的连接,但是listen 443 ssl;却说要监听端口 443 上的https连接。

配置如下:

server {
    listen 80;
    server_name mydomain.net;
    return 301 https://mydomain.net$request_uri;
}

server {
    listen 443 ssl;
    server_name mydomain.net;

    ssl_certificate           /etc/letsencrypt/live/mydomain.net/fullchain.pem;
    ssl_certificate_key       /etc/letsencrypt/live/mydomain.net/privkey.pem;

    location / {
        proxy_pass http://myip:myport;
    }
}

您还可以将它们组合起来。您可以删除返回语句,并将所有其他语句组合成一个服务器块。只需添加此代码片段:

  if ($scheme = http) {
    return 301 https://$host$uri?$args;
  }

相关内容