【问题标题】:Configuring NGINX as reverse-proxy (to dispatch) to backend services that are already SSL configured将 NGINX 配置为反向代理(以分派)到已配置 SSL 的后端服务
【发布时间】:2020-06-02 20:02:29
【问题描述】:

我有一台物理服务器和一台IP address。在该服务器上,我配置了三个(数量 3)后端服务,每个都有自己的公共 DNS 域名每个都有自己的 Let's Encrypt SSL certificates,如图所示:

 - svc01.example.com:1443  # Own DNS domain-name and SSL certificates.
 - svc02.example.com:2443  # Own DNS domain-name and SSL certificates.
 - svc03.example.com:3443  # Own DNS domain-name and SSL certificates.

它们在同一个物理服务器上共存,因此每个都配置为使用自己的Port;但是,svc01|02|03.example.compublic IP-Address 是相同的。

请记住,这些后端服务已经配置了 SSL(我无法撤消),如何配置 NGINX 以实现以下简单转发(几乎像调度程序) :

 svc01.example.com:443  --> svc01.example.com:1443
 svc02.example.com:443  --> svc02.example.com:2443
 svc03.example.com:443  --> svc03.example.com:3443

很遗憾,我不是NGINX 的人,因此非常感谢为每个人提供完整的配置文件:

- svc01_nginx.conf
- svc02_nginx.conf
- scv03_nginx.conf

提前谢谢你!

【问题讨论】:

  • @SteffenUllrich 谢谢!我看了看,它看起来像我需要的方向。 :)
  • @SteffenUllrich 仅供参考:如果您在我的问题中使用服务器名称和场景编写了一个完整的(可剪切和粘贴的)答案,我将对其进行投票并可能选择它作为答案。谢谢。
  • 很高兴为您提供正确的提示。但请根据我给您的提示随意回答这个问题。

标签: ssl nginx nginx-reverse-proxy


【解决方案1】:

感谢@SteffenUllrich 在上面的cmets 中提供的提示,解决方案如下图所示。不是nginx 的人,我不确定是否有其他最佳实践可以使此配置更安全或更强大(免费评论),但这是一个开始。

/etc/nginx/nginx.conf:

load_module /usr/lib/nginx/modules/ngx_stream_module.so;
  
events {}

stream {    
  map $ssl_preread_server_name $targetBackend {
    svc01.example.com svc01.example.com:1443
    svc02.example.com svc02.example.com:2443
    svc03.example.com svc03.example.com:3443    
  }

  server {
    listen 8443;    
    # ==============================================================
    # http://nginx.org/en/docs/stream/ngx_stream_proxy_module.html
    # ==============================================================
    proxy_connect_timeout 10s;
    proxy_timeout 600s;
    resolver 8.8.8.8 1.1.1.1 8.8.4.4 1.0.0.1;
    proxy_pass $targetBackend;
    # ==============================================================

    # ==============================================================
    # http://nginx.org/en/docs/stream/ngx_stream_ssl_preread_module.html
    # ==============================================================
    ssl_preread on;
    # ==============================================================
  }
}

我希望这对其他人有所帮助。 (◠﹏◠)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-14
    • 1970-01-01
    • 2018-03-02
    • 1970-01-01
    • 2023-04-02
    相关资源
    最近更新 更多