首页 > 解决方案 > NGINX 反向代理的 Certbot/LetsEncrypt HTTPS 不起作用

问题描述

我一直在尝试为我的网站设置 SSL 无济于事。我在 Ubuntu 18.04 上使用 NGINX 作为两个 NodeJS Express Web 服务器的反向代理。我按照这些说明使用了 Certbot 。但是,当尝试通过 HTTPS 访问我的站点时,我收到“无法访问站点”/“响应时间过长”错误。

这是我的 NGINX 配置的/etc/nginx/sites-available样子:

server {

    listen [::]:443 ssl; # managed by Certbot
    listen 443 ssl;  # managed by Certbot
    server_name MYURL.com www.MYURL.com;

    ssl on;

    ssl_certificate /etc/letsencrypt/live/MYURL.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/MYURL.com/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

    access_log /var/log/nginx/MYURL.access.log;
    error_log /var/log/nginx/MYURL.error.log;

    client_max_body_size 50M;

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

            proxy_pass https://localhost:3001;
    }
}

当我将listen [::]:443 sslandlisten 443 ssl行替换为listen 80;并尝试使用 HTTP 访问该站点时,它工作正常。

知道问题可能是什么吗?


编辑:另外,我觉得我应该提到我的 UFW 状态有 22/tcp (LIMIT)、OpenSSH (ALLOW) 和 Nginx Full (ALLOW),以及它们的 v6 对应状态

标签: sslnginxhttps

解决方案


事实证明 DigitalOcean 防火墙不允许 HTTPS 连接。我允许 HTTPS 并切换proxy_pass https://localhost:3001;http://,现在一切正常!


推荐阅读