如何代理公司内网的数据库,使其在居家办公的时候顺利进行开发

我的办公电脑由于存储空间太小,不能顺利安装开发数据库,于是便使用公司内网的测试数据库作为我的开发数据库。可是有些某些原因需要居家办公的时候,如果不能通过公网IP访问数据库,开发过程会便得极为不利,以下纪录我如何通过openResty反向代理公司内网Tcp,实现外网顺利开发得。
注意:你需要有自己的公网服务器和公网IP,并配置好服务端的Frp。

1、下载openResty,https://openresty.org/download/openresty-1.21.4.1-win64.zip
2、解压后,在conf文件夹下找到nginx.conf与http节点同级添加以下内容

stream{
	upstream SCZL1433 {
		hash $remote_addr consistent;
		server 192.168.xxx.164:1433     max_fails=3 fail_timeout=30s; # 在公司办公电脑能访问到的内网地址
	}

	server {
		listen 33062; # 这个端口作为frp的内网端口
		proxy_connect_timeout 5s;
		proxy_timeout 300s;
		proxy_pass SCZL1433;
	}
}

3、修改自己的frpc.ini文件,与本文相关的只有[common],[sqlserver]

[common]
server_addr = 148.xxx.xxx.xxx # 我的公网IP
server_port = 7000

[ssh] #远程桌面配置
type = tcp
local_ip = 127.0.0.1
local_port = 3389 
remote_port = 6000

[web] #代理http
type = http
local_port = 80
custom_domains = xxx.xxx.top # 已备案的域名

[sqlserver]
type = tcp
local_ip = 127.0.0.1
local_port = 33062 # nginx.conf -> server -> listen 33062;
remote_port = 1344 #通过你的外网IP,此端口即可访问公司内网数据库了

重启nginx和frp之后即可。

posted @ 2022-12-02 11:34  xuxuzhaozhao  阅读(168)  评论(0编辑  收藏  举报