是否可以根据主机名重定向TCP连接?

问题描述 投票:1回答:1

我想做的就是像这样连接到Postgres服务器:

psql -h postgres-a.example.com -p 9000

该连接应由代理服务器(如nginx或haproxy)接收,由于主机名postgres-a.example.com,它将被重定向到数据库A。如果我使用postgres-b.example.com和相同的端口,则应转到数据库B。

我一直在对此进行研究,但是我仍然不确定100%如何工作。我读到唯一基于主机名重定向TCP连接(psql)的方法是使用SNI标头。但是我仍然不知道我们是否需要SSL证书,或者是否需要使用https://postgres-a.example.com(对我来说这没有任何意义)。它将如何工作?

有人可以帮我理解吗?

postgresql http nginx tcp haproxy
1个回答
0
投票

是。您将需要TLS / SSL证书,并且可以基于req.ssl_sni将请求路由到适当的后端。我不确定psql是否使用SNI,但我认为这可以让您检查。

frontend public_ssl

  bind :::9000 v4v6 crt /usr/local/etc/haproxy-certs

  option tcplog

  tcp-request inspect-delay 5s
  tcp-request content accept if { req.ssl_hello_type 1 }

  use-server postgres-a if { req.ssl_sni -i postgres-a.example.com }
  use-server postgres-b if { req.ssl_sni -i postgres-b.example.com }

backend postgres-a
    server postgres-a FURTHER SERVER PARAMS

backend postgres-b
    server postgres-b FURTHER SERVER PARAMS

我创建了一个带有图片的博客文章,以进行更详细的描述。https://www.me2digital.com/blog/2019/05/haproxy-sni-routing/

© www.soinside.com 2019 - 2024. All rights reserved.