[英]How to enable fastify's http2 in Digital Ocean app platform
我正在嘗試弄清楚如何為我的 rest api 啟用 http2。我使用 fastify 作為其服務器,根據他們的文檔,可以通過以下方式啟用安全的 http2
https://www.fastify.io/docs/latest/Reference/HTTP2/
我現在面臨的問題是這個 api 在多個服務器實例上部署到https://www.digitalocean.com/products/app-platform (為了可靠性和可擴展性)
如果我理解正確的話,流量是通過 cloudflare 路由到這些實例的,它是開箱即用的。 在這種情況下,我假設 cloudflare 還管理所有 ssl 證書。
因此我的問題是,如何在此設置中指定要固定的證書文件(那些.key
和.cert
文件)? 我無權訪問 cloudflare 帳戶,因為它由 Digital Ocean 管理。
根據 DigitalOcean App Platform 文檔,您似乎只能為自定義域啟用 HTTPS,而不能為默認應用程序平台域 (your-app.ondigitalocean.app) 啟用。
https://docs.digitalocean.com/products/app-platform/quickstart/#register-a-custom-domain
如果你想為你的應用啟用 HTTPS,你需要添加一個自定義域,然后為該域添加一個 SSL 證書。
https://docs.digitalocean.com/products.networking/load-balancers/how-to/manage/#ssl
根據 Fastify 文檔,為了啟用 HTTPS/HTTP2,您需要在初始化 Fastify 服務器時在選項 object 中指定密鑰和證書文件。
https://www.fastify.io/docs/latest/Reference/HTTP2/#http2
由於您無權訪問 Cloudflare,您可以使用 Lets Encrypt 獲得 SSL 證書。
激活SSL
和HTTPS
的最常見方法之一是使用 let's encrypt 和certbot
。為此,請在雲 SHELL 中執行以下步驟:
sudo add-apt-repository ppa:certbot/certbot sudo apt-get update sudo apt-get install python-certbot-nginx sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com # Only valid for 90 days, test the renewal process with certbot renew --dry-run
還要檢查此參考資料,它對我很有用。 查看
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.