因此我的 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 指令更改为 listen与SSL协议: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;
}