通过另一台服务器中继 PostgreSQL 连接
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15768913/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Relay PostgreSQL connection over another server
提问by Jochen Ritzel
I'm using a PostgreSQL database on a remote server with a very restrictive firewall that only allows connections from our webserver. This makes developing stuff on my own workstation pretty difficult, as I cannot connect to this server directly to test my code.
我在远程服务器上使用 PostgreSQL 数据库,防火墙非常严格,只允许来自我们的网络服务器的连接。这使得在我自己的工作站上开发东西变得非常困难,因为我无法直接连接到这个服务器来测试我的代码。
What I'd like to do is set up some sort of proxy on our webserver that simply sends all queries to the firewalled server. Then I can use our server from my workstation to test my code. Any ideas how to do this or other ways that solve my problem?
我想做的是在我们的网络服务器上设置某种代理,将所有查询发送到防火墙服务器。然后我可以从我的工作站使用我们的服务器来测试我的代码。任何想法如何做到这一点或解决我的问题的其他方法?
回答by DAB
use ssh and create a local tunnel, something like this (only works if you have an ssh daemon running on web server)
使用 ssh 并创建一个本地隧道,就像这样(仅当您在 Web 服务器上运行 ssh 守护程序时才有效)
ssh [email protected] -CNL localhost:5432:192.168.1.128:5432
The above will listen on 5432 (postgres port) on localhost and forward all traffic to remote machine via the web server.
以上将侦听 localhost 上的 5432(postgres 端口),并通过 Web 服务器将所有流量转发到远程机器。
As mentioned below by Ricky Han, you need to change the address 192.168.1.128 to that of your PostgreSQL server.
正如下面 Ricky Han 提到的,您需要将地址 192.168.1.128 更改为您的 PostgreSQL 服务器的地址。
Obviously you will need to change the name of webserver.com as well! :-)
显然,您还需要更改 webserver.com 的名称!:-)