让我们用Sails.js加密

时间:2015-12-23 10:37:19

标签: sails.js lets-encrypt greenlock

有没有人能够使用带有Sails.js的let加密节点模块(https://git.coolaj86.com/coolaj86/greenlock-express.js)?一个小指针会有所帮助。

2 个答案:

答案 0 :(得分:1)

是的,您可以使用greenlock-express.jsLetsEncrypt节点环境中直接通过Sails实现SSL。

以下示例:

  1. 配置一个HTTP表达应用程序中使用的端口80 greenlock处理该 重定向到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之类的地方。

答案 1 :(得分:0)

我不得不将绿色锁降级到版本2。

相关问题