首先,你须要这几样东西。node
npm install express
。步骤1:安装包python
EPEL(Extra Packages for Enterprise Linux)资源库中包含了咱们安装Certbot所须要的全部包,因此咱们先设置一下。web
yum -y install epel-release
接下来,咱们将安装两个让Let's Encrypt运行所需的软件包:certbot和apache链接器。shell
yum -y install certbot python-certbot-apache
第二,你将用certbot生成一个SSL证书。express
`$ certbot certonly --manual`。
这张图是用碳生成的,我很是喜欢这个工具(感谢都灵先生)apache
输入你的域名,不包括协议部分。例如 例如:yourdomain.com或甚至muchdomain.verysite.。npm
输入Y而后ENTER.。浏览器
注意两点。安全
**如今,不要继续了。你须要用 Node 和 Express 运行一个 web 服务器。服务器
在某个地方打开你的终端
.well-known
,并在这个目录下建立:acme-challenge
。acme-challenge
中放入你以前建立的文件:a-string。这是你应该有的。
`server
----.well-known
--------acme-challenge
------------a-string
---server.js`
重要:其实文件名并非个字符串,是一个很长的字母数字字符串。为了安全起见,我不能给你看个人。一样的,一个挑战也是如此......
使用你最喜欢的代码编辑器并复制粘贴此代码。
// Dependencies const express = require('express'); // Configure & Run the http server const app = express(); app.use(express.static(__dirname, { dotfiles: 'allow' } )); app.listen(80, () => { console.log('HTTP server running on port 80'); });
为了验证一切正常,请打开浏览器并导航到 。*http://yourdomain.com/.well-known/acme-challenge/a-string
你的浏览器应该下载你的挑战文件。若是不是这样,请从头开始恢复一切。不要碰你的shell,从目录和文件建立从新启动。
若是一切正常,回到你的shell,输入ENTER.。
万岁,最后一步,你就完成了!。
**复制粘贴如下代码,你将有一个全新的HTTPS服务器运行。
// Dependencies const fs = require('fs'); const http = require('http'); const https = require('https'); const express = require('express'); const app = express(); // Certificate const privateKey = fs.readFileSync('/etc/letsencrypt/live/yourdomain.com/privkey.pem', 'utf8'); const certificate = fs.readFileSync('/etc/letsencrypt/live/yourdomain.com/cert.pem', 'utf8'); const ca = fs.readFileSync('/etc/letsencrypt/live/yourdomain.com/chain.pem', 'utf8'); const credentials = { key: privateKey, cert: certificate, ca: ca }; app.use((req, res) => { res.send('Hello there !'); }); // Starting both http & https servers const httpServer = http.createServer(app); const httpsServer = https.createServer(credentials, app); httpServer.listen(80, () => { console.log('HTTP Server running on port 80'); }); httpsServer.listen(443, () => { console.log('HTTPS Server running on port 443'); });
导航到: https://yourdomain.com, 你应该会看到 "Hello there !".
好了,你已经到了本教程的最后。
最后一句话:*你可能会遇到错误,请从头开始重启教程。
"白色杯子里的卡布奇诺,木桌上的白色泡沫艺术 "由wu yi在Unsplash上发布。
使用www.DeepL.com/Translator翻译(免费版)