大网数据广告活动
网站运营与故障问答

How to run multiple Node.js sites (apps/servers) with separate SSL cert's, on a single IP address?

· 52CE 我爱测

The desired scenario is as the title suggests: Multiple Node.js servers/apps/websites, on separate domains, each with own SSL certificate, on a single server with a single IP address. So far I have tried: A proxy catching all inc…

问题原文

原帖链接 · marko-36 · CC BY-SA 4.0

The desired scenario is as the title suggests: Multiple Node.js servers/apps/websites, on separate domains, each with own SSL certificate, on a single server with a single IP address. So far I have tried:

  • A proxy catching all incoming requests and forwarding them to respective apps/servers, on separate, non-443 ports: Does not work, since the proxy server can only run on a single SSL certificate, which will throw an error for all but one of the domains.

  • Apps running on different ports and DNS pointing at these ports: Does not work, since an HTTPS connection, will always go to port 443. The SRV DNS record can't change this, for ports 443 and 80.

  • Using a single SSL cert issued for an IP address: Is somehow possible, but after doing some research on this, it is not such a good idea.

  • Servers responding to specific hostnames: httpsServer.listen(443,'domain.name') throws Error: listen EADDRNOTAVAIL 123.456.789.000:443. This is where I expected the server to ignore all requests but those where hostname is the domain.name. But still, you can't run multiple servers on a single port.

So back to square one: what I need is a proxy, which establishes a connection with an SSL certificate for the specific requested hostname, and forwards the request to an app/server running on a unique port. How? EDIT: Using Nginx, or other proxy/firewall software is certainly an option, but at this point, I am trying to find out a Node.js-only solution.

已采纳解答

原帖链接 · Maximillian Laumeister · CC BY-SA 4.0

You can use redbird, a Node.js reverse proxy. Your config will look something like this

var proxy = require('redbird')({port: 80});

proxy.register("example1.com", "http://127.0.0.1:8001", {
  ssl: {
    letsencrypt: {
      email: '[email omitted]', // Domain owner/admin email
      production: true, // WARNING: Only use this flag when the proxy is verified to work correctly to avoid being banned!
    }
  }
});

proxy.register("example2.com", "http://127.0.0.1:8002", {
  ssl: {
    letsencrypt: {
      email: '[email omitted]', // Domain owner/admin email
      production: true, // WARNING: Only use this flag when the proxy is verified to work correctly to avoid being banned!
    }
  }
});

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2018-11-11)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。