Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postgresql 是否可以根据主机名重定向TCP连接?_Postgresql_Http_Nginx_Tcp_Haproxy - Fatal编程技术网

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

Postgresql 是否可以根据主机名重定向TCP连接?,postgresql,http,nginx,tcp,haproxy,Postgresql,Http,Nginx,Tcp,Haproxy,我希望能够这样连接到postgres服务器: psql-h postgres-a.example.com-p9000 该连接应由代理服务器(如nginx或haproxy)接收,并且由于主机名postgres-a.example.com,它将被重定向到数据库a。如果我使用postgres-b.example.com和相同的端口,它应该转到数据库b 我一直在研究这一点,但我仍然不能100%确定这将如何工作。我了解到,根据主机名重定向TCP连接(psql)的唯一方法是使用SNI头。但是我仍然不明白我们

我希望能够这样连接到postgres服务器:

psql-h postgres-a.example.com-p9000

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

我一直在研究这一点,但我仍然不能100%确定这将如何工作。我了解到,根据主机名重定向TCP连接(psql)的唯一方法是使用SNI头。但是我仍然不明白我们是否需要SSL证书,或者是否需要使用
https://postgres-a.example.com
(这对我来说毫无意义)。它将如何工作


有人能帮我理解吗?

是的。您需要TLS/SSL证书,并且可以基于
req.SSL\u 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
我已经创建了一篇带有图片的博文,以获得更详细的描述。
http(s)
是web服务器的协议
psql
可能使用专有协议与其数据库服务器进行通信
http(s)
将主机名作为初始请求的一部分发送,Nginx理解此协议,这就是为什么它可以基于主机名反向代理。完全有可能
psql
不发送主机名,而且在任何情况下,Nginx都无法确定主机名,因此简短的回答是否定的。