ssl - 如何使用 cloudflare 使服务器上的 API 安全 (HTTPS)

标签 ssl https digital-ocean cloudflare

我刚刚使用 CloudFlare 的 SSL 证书保护了我的域。而且效果很好!

但我仍然有一个问题,我有一个快速服务器,我在 myIpAddress:2053/api/request 上使用服务 API,但我生成的证书不适用于它。

它仍然告诉我 API 不安全,我必须在 Google Chrome 和其他浏览器上使用 (Advanced => Proceed to ------- (unsafe))。

这是我的代码的一个高峰。

const privateKey = fs.readFileSync("/etc/ssl/private/key.pem", “utf8”); //CF’s SSL key
const certificate = fs.readFileSync("/etc/ssl/certs/cert.pem", “utf8”); //CF’s SSL cert
let credentials = { key: privateKey, cert: certificate };
let httpsServer = https.createServer(credentials, app);
httpsServer.listen(PORT, () => {
console.log(HTTPS started on port ${PORT});
});

为了与前端通信,我的 API 也必须是安全的。它应该类似于:**https**://myIpAddress:2053/api/request

我的服务器在 DigitalOcean 上,使用 Ubuntu 作为操作系统和 NGINX。

最佳答案

当浏览器与服务器进行ssl握手时,浏览器会检查与ssl证书中Subject CN匹配的域名。

这是查看证书的命令:

openssl x509 -inform PEM -text -in ssl.crt

enter image description here

关于ssl - 如何使用 cloudflare 使服务器上的 API 安全 (HTTPS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57066567/

相关文章:

.htaccess - 为什么我的网站 URL 末尾有双斜杠,例如 ://

ssh - 当服务器 ssh key 有密码时,Capistrano 部署失败

node.js - DigitalOcean 停止使用 nohup 运行的 Node.js 服务器

python - 连接到安装在不同服务器上的 MongoDb DB

ssl - 从 ssl 站点抓取表单并自己使用

ssl - connection.startTls() 失败

google-chrome - 如何让 Chrome 允许混合内容?

url - 如何在我网站的网址上制作这个?

c# - 已成功与服务器建立连接,但在登录过程中出现错误。目标主体名称不正确

security - 谷歌应用引擎的 ssl 是免费的吗?