繁体   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