簡體   English   中英

讓我們用 Sails.js 加密

[英]Let's encrypt with Sails.js

有沒有人能夠在 Sails.js 中使用讓我們加密節點模塊( https://git.coolaj86.com/coolaj86/greenlock-express.js )? 一個小指針會有所幫助。

是的,您可以使用greenlock-express.js直接在Sails節點環境中通過LetsEncrypt實現 SSL。

下面的例子:

  1. 使用端口 80 上的 greenlock 配置 HTTP express 應用程序,該應用程序處理重定向到 HTTPS 和 LetsEncrypt 業務邏輯。
  2. 使用 greenlock SSL 配置將主要 Sails 應用程序配置為端口 443 上的 HTTPS。

config/local.js示例配置:

// returns an instance of greenlock.js with additional helper methods
var glx = require('greenlock-express').create({
  server: 'https://acme-v02.api.letsencrypt.org/directory'
  , version: 'draft-11' // Let's Encrypt v2 (ACME v2)
  , telemetry: true
  , servername: 'domainname.com'
  , configDir: '/tmp/acme/'
  , email: 'myemail@somewhere.com'
  , agreeTos: true
  , communityMember: true
  , approveDomains: [ 'domainname.com', 'www.domainname.com' ]
  , debug: true
});

// handles acme-challenge and redirects to https
require('http').createServer(glx.middleware(require('redirect-https')())).listen(80, function () {
  console.log("Listening for ACME http-01 challenges on", this.address());
});

module.exports = {
  port: 443,
  ssl: true,
  http: {
    serverOptions: glx.httpsOptions,
  },
};

請參閱 greenlock 文檔以了解微調配置詳細信息,但以上內容提供了一個開箱即用的 LetsEncrypt 與 Sails 一起使用。

另請注意,您可能希望將此配置適當地放置在config/env/production.js類的地方。

我不得不將綠色鎖降級到版本 2。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM