首页 > 解决方案 > 使用 https 时从公共 IP 拒绝 AWS 连接

问题描述

我有一个 python-flask Web 应用程序在 AWS EC2 实例上的 docker 中运行。我正在使用 python-sslify 强制使用 https,但我收到“连接被拒绝”。我确保在安全组的入站规则中打开了 80 端口,并打开了 443 端口。如果我关闭 sslify,一切运行正常,只是不安全。使用 sslify 我得到以下信息:

$ curl https://localhost
curl: (35) gnutls_handshake() failed: The TLS connection was non-properly terminated.
$ curl https://ec2-**-**-***-***.compute-1.amazonaws.com/login
curl: (7) Failed to connect to ec2-**-**-***-***.compute-1.amazonaws.com port 443: Connection refused

据我所知,gnutls_handshake 错误是旧版本 curl 的问题,所以我得出的结论是它工作正常,只是没有对互联网开放。查看服务器的调试输出,我可以看到一个连接进来,接收到 302 重定向到 https,但就是这样。端口 80 肯定是开放的并且工作正常,端口 443 不是,我不知道为什么。除了安全组的入站规则之外,我还需要在其他地方打开端口 443 吗?

这是入站规则,顺便说一句。此外,服务器在 docker 中的 0.0.0.0:8000 上运行,端口 80、443 和 8000 已暴露。 入境规则

编辑:请求 telnet 443:

$ telnet localhost 443
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Connection closed by foreign host.
$ telnet ec2-**-**-***-***.compute-1.amazonaws.com 443
Trying **-**-***-***...
telnet: Unable to connect to remote host: Connection refused

编辑 2:Netstat 测试:

$ netstat -a -n -t | grep ':443.*LISTEN'
tcp6       0      0 :::443                  :::*                    LISTEN

标签: pythonamazon-web-servicesdockerflaskamazon-ec2

解决方案


推荐阅读