将Greenlock绑定到特定的IP地址?

时间:2020-02-05 05:06:11

标签: node.js greenlock

我的Greenlock Express在Windows服务器上的node.js中运行良好。但是,我向服务器添加了更多IP地址,发现node.js和greenlock正在侦听0.0.0.0上的端口443,从而占用了所有IP地址。

如何告诉greenlock仅在一个特定IP地址上监听端口443?

我可以添加任何配置值吗?

var greenlock = require('greenlock-express')
    .init({ 
        packageRoot: __dirname,
        maintainerEmail: "....",
        configDir: './greenlock.d',
        cluster: false
     });

1 个答案:

答案 0 :(得分:1)

那是在示例文件夹https://git.rootprojects.org/root/greenlock-express.js/src/branch/master/examples/https/server.js

这是您需要用于更高级用途的文件夹。

"use strict";

// The WRONG way:
//var https = require('https');
//var httpsServer = https.createServer(tlsOptions, app);
//
// Why is that wrong?
// Greenlock needs to change some low-level http and https options.
// Use glx.httpsServer(tlsOptions, app) instead.

//require("greenlock-express")
require("../../")
    .init({
        packageRoot: __dirname,
        configDir: "./greenlock.d",

        maintainerEmail: "jon@example.com",
        cluster: false
    })
    .ready(httpsWorker);

function httpsWorker(glx) {
    //
    // HTTPS 1.1 is the default
    // (HTTP2 would be the default but... https://github.com/expressjs/express/issues/3388)
    //

    // Get the raw https server:
    var httpsServer = glx.httpsServer(null, function(req, res) {
        res.end("Hello, Encrypted World!");
    });

    httpsServer.listen(443, "0.0.0.0", function() {
        console.info("Listening on ", httpsServer.address());
    });

    // Note:
    // You must ALSO listen on port 80 for ACME HTTP-01 Challenges
    // (the ACME and http->https middleware are loaded by glx.httpServer)
    var httpServer = glx.httpServer();

    httpServer.listen(80, "0.0.0.0", function() {
        console.info("Listening on ", httpServer.address());
    });
}

我看到您留下了一个问题(昨天?),但是我忘了回复。