【问题标题】:Bind Greenlock to specific ip address?将Greenlock绑定到特定的IP地址?
【发布时间】:2020-02-05 05:06:11
【问题描述】:

我在我的 Windows 服务器上的 node.js 中运行良好的 greenlock express。但是,我在服务器上添加了更多 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
     });

【问题讨论】:

    标签: node.js greenlock


    【解决方案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());
        });
    }
    

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

    【讨论】:

    • 当我这样做时,我现在得到这个错误:Error [ERR_SERVER_ALREADY_LISTEN] [ERR_SERVER_ALREADY_LISTEN]: Listen method has been called more than once without closing.
    • 听起来像是一个陈旧的绑定(或另一个服务在同一地址和端口上侦听)。尝试重新启动并使用 netstatsystemctl 以确保没有其他使用它们的运行。
    • 我收到以下错误TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string。但我不知道它在说哪个path
    猜你喜欢
    • 2012-04-16
    • 2012-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-28
    • 2023-02-12
    • 1970-01-01
    • 2016-03-08
    相关资源
    最近更新 更多