Nginx letsencrypt certbot ssl 页面不会通过 https 加载,但会通过 http 加载

Nginx letsencrypt certbot ssl 页面不会通过 https 加载,但会通过 http 加载

我正在尝试使用本教程设置数字海洋服务器https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-16-04

该网站通过 HTTP 可以正常访问,但无法通过 https 加载。(不会加载引用此 chrome 错误)

This site can’t be reached kronoswebsolutions.com took too long to respond.
Try:

Checking the connection
Checking the proxy and the firewall
ERR_CONNECTION_TIMED_OUT

根据建议,我在发布之前确实检查了防火墙,但这是我的 ufw 的输出。我没有在我的数字海洋 droplet web gui 上启用防火墙。

Nginx Full                 ALLOW       Anywhere                  
22                         ALLOW       *************             
22                         ALLOW       *************             
OpenSSH                    ALLOW       Anywhere                  
Nginx Full (v6)            ALLOW       Anywhere (v6)             
OpenSSH (v6)               ALLOW       Anywhere (v6)     
Here is the results of nmap from my local machine using the ip of my server...

nmap -Pn -p 443 IPADDRESS
Starting Nmap 7.70 ( https://nmap.org ) at 2019-05-07 23:46 MDT
Nmap scan report for IPADDRESS
Host is up.

PORT    STATE    SERVICE
443/tcp filtered https

我使用的是 Debian stretch 而不是 Ubuntu。

答案1

看起来这肯定是防火墙问题。我用它重置了 iptables 中的防火墙设置,然后再次设置了 ufw,它就可以正常工作了。

首先,将每个内置链的默认策略设置为“接受”。这样做的主要原因是为了确保您不会通过 SSH 被锁定在服务器之外:

$ sudo iptables -P INPUT ACCEPT
$ sudo iptables -P FORWARD ACCEPT
$ sudo iptables -P OUTPUT ACCEPT

然后刷新 nat 和 mangle 表,刷新所有链(-F),并删除所有非默认链(-X):

$ sudo iptables -t nat -F
$ sudo iptables -t mangle -F
$ sudo iptables -F
$ sudo iptables -X

然后重新启用 ufw

$ sudo ufw enable

答案2

我按照这个做了之后也遇到了同样的问题教程事实证明它缺少了您必须添加到您网站的 nginx.conf 中的这段代码:

listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/{{ domain }}/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/{{ domain }}/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

相关内容