[英]How can I use a LetsEncrypt SSL cert in my Heroku Node Express app?
我有一個在Heroku上運行的Node Express應用程序,我希望使用LetsEncrypt的免費SSL證書進行加密。 但是,我看到的方法需要打開端口443和80以允許ACME進程工作。
Heroku只給你一個端口,不允許你選擇哪個端口。 那么我該如何使用LetsEncrypt呢?
昨天我花了很多時間搞清楚這一點。 很久以來第一次在StackOverflow上找不到我想做的事情的答案!
Heroku現在本地支持LetsEncrypt! 因此不再需要此解決方法。
說明:
https://devcenter.heroku.com/articles/automated-certificate-management
對於新應用,您無需執行任何操作,默認情況下已啟用此功能。 對於2017年3月21日之前創建的應用程序,您可以使用此Heroku cli命令打開它: heroku certs:auto:enable
謝謝@Spain Train
理想情況下,LetsEncrypt允許自動證書續訂過程。 這在Heroku上很難做到,所以這個答案描述了如何使用手動過程。 使用Heroku環境var,您將能夠非常輕松地手動更新證書 - 無需更改代碼。
這個答案很大程度上歸功於兩篇不錯的博文: https : //medium.com/@franxyzxyz/setting-up-free-https-with-heroku-ssl-and-lets-encrypt-80cf6eac108e#.67pjxutaw
和
https://medium.com/should-designers-code/how-to-set-up-ssl-with-lets-encrypt-on-heroku-for-free-266c185630db#.ldr9wrg2j
有一個GitHub項目顯然支持Heroku上的自動化證書更新。 我試用后會更新這個答案:
https://github.com/dmathieu/sabayon
將此中間件添加到Express應用程序中。 確保在將http重定向到https的任何中間件之前添加它,因為此端點必須是http。
// Read the Certbot response from an environment variable; we'll set this later:
const letsEncryptReponse = process.env.CERTBOT_RESPONSE;
// Return the Let's Encrypt certbot response:
app.get('/.well-known/acme-challenge/:content', function(req, res) {
res.send(letsEncryptReponse);
});
sudo certbot certonly --manual
sudo ls /etc/letsencrypt/live/www.example.com
以查看文件是否存在。 運行heroku certs:add
如果您的站點沒有heroku certs:add
。 如果更新,請運行heroku certs:update
。
sudo heroku certs:update --app your-heroku-app-name /etc/letsencrypt/live/www.example.com/fullchain.pem /etc/letsencrypt/live/www.example.com/privkey.pem
您還可以將域名所有權驗證為讓我們使用DNS加密而不是HTTP。
使用certbot
,將DNS指定為首選挑戰:
sudo certbot certonly --manual --preferred-challenges dns
在幾次提示之后,certbot會告訴您保留DNS TXT記錄以驗證您的域名:
Please deploy a DNS TXT record under the name
_acme-challenge.www.codesy.io with the following value:
CxYdvM...5WvXR0
Once this is deployed,
Press ENTER to continue
您的域名注冊商可能擁有自己的部署TXT記錄的文檔。 這樣做,然后返回到certbot
並按ENTER鍵 - 讓我們加密將檢查TXT記錄,簽署證書, certbot
將保存它以便您上傳到heroku。
有關詳情,請參閱我的詳細博文 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.