如何使用 Cloudflare SSL 证书设置简单的 https 服务器? [英] How to set up a simple https server using a Cloudflare SSL certificate?

查看:171
本文介绍了如何使用 Cloudflare SSL 证书设置简单的 https 服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法通过 https 连接我的服务器.

I can't seem to get my server to connect over https.

我创建了一个免费的 Cloudflare 帐户以获取用于测试服务器的免费 SSL 证书.我从 Cloudflare 将原始证书和密钥下载到我在 Google Cloud Platform 上运行的 Ubuntu 服务器上.

I created a free Cloudflare account to get a free SSL certificate for a test server. I downloaded the origin certificate and key from Cloudflare onto my Ubuntu server running on the Google Cloud Platform.

在防火墙选项中允许端口 443 上的 https.

https on port 443 is allowed in firewall options.

我尝试创建一个简单的 python https 服务器,如下所示:

I tried to create a simple python https server as shown here:

from socketserver import TCPServer
from http.server import SimpleHTTPRequestHandler
from ssl import wrap_socket

httpd = TCPServer(('localhost', 443), SimpleHTTPRequestHandler)
httpd.socket = wrap_socket(httpd.socket, certfile='./cert.pem', keyfile='./cert.key', server_side=True)
httpd.serve_forever()

它运行时没有错误,但不产生任何输出.我尝试通过访问 https://ip_address 而不指定端口来从浏览器连接,因为我认为 https 默认连接到端口 443.

It runs with no errors but does not produce any output. I try to connect from the browser by accessing https://ip_address without specifying the port since I think https connects to port 443 by default.

我在端口 80 上运行了一个简单的 http 服务器,并且工作正常.

I ran a simple http server on port 80 and that worked.

我希望在通过 https 连接的目录中看到基本的 html 页面,但我在浏览器中得到了 ERR_CONNECTION_REFUSED.

I'm expecting to see the basic html page in the directory connected over https, but I get ERR_CONNECTION_REFUSED in the browser instead.

推荐答案

localhost 更改为 0.0.0.0.

Localhost 只接受来自机器内部的连接.这是环回地址.

Localhost only accepts connections from inside the machine. This is the loopback address.

0.0.0.0 表示绑定到所有可用网络.这接受来自机器外部和内部的连接.

0.0.0.0 means bind to all available networks. This accepts connections from outside and inside the machine.

这篇关于如何使用 Cloudflare SSL 证书设置简单的 https 服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆