首先,你須要這幾樣東西。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翻譯(免費版)