计算机 · 2022年12月3日 0

内网穿透工具

https://cloud.tencent.com/developer/article/1941962

https://www.v2ex.com/t/567570

frp

https://github.com/fatedier/frp/tree/master

文档

https://gofrp.org/docs/reference/proxy/

编译

make

编译时出错:

cannot load embed: malformed module path "embed": missing dot in first path element

原因是服务器使用的go版本是1.13,而embed这个模块需要在更高版本的go中才有。

安装高版本的方式:

方式一:官网下载安装包安装;

方式二:安装ppa

https://launchpad.net/~longsleep/+archive/ubuntu/golang-backports

安装ppa时遇到错误:sudo: apt-add-repository: command not found?

那就再安装下这个apt-add-repository命令:

https://linuxconfig.org/sudo-apt-add-repository-command-not-found

也就是要安装一下software-properties-common这个命令。

安装golang-backports后

sudo apt update
sudo apt install golang-go

使用docker版本

也可以直接使用docker镜像,不用自己编译。

https://registry.hub.docker.com/r/snowdreamtech/frps/

服务器端:

docker run --restart=always --network host -d -v /etc/frp/frps.ini:/etc/frp/frps.ini --name frps snowdreamtech/frps

客户端:

docker run --restart=always --network host -d -v /etc/frp/frpc.ini:/etc/frp/frpc.ini --name frpc snowdreamtech/frpc

使用

具体见readme文件。

反向代理tcp端口

# frpc.ini
[common]
server_addr = x.x.x.x
server_port = 7000

[ssh]
type = tcp
local_ip = 127.0.0.1
local_port = 22
remote_port = 6000

反向代理一个http服务

服务端配置文件

# frps.ini
[common]
bind_port = 7000
vhost_http_port = 8080

客户端配置文件

# frpc.ini
[common]
server_addr = x.x.x.x
server_port = 7000

[web]
type = http
local_port = 80
custom_domains = www.example.com

外网访问地址:http://www.example.com:8080

这里的vhost_http_port相当于nginx监听的外网端口,custom_domains则相当于按请求的域名决定将请求分发给哪一个frpc客户端。

https2http

可以通过https2http插件让frp将外网的https请求转换为对内网的http请求。

服务端配置:

增加vhost_https_port配置。

# frps.ini
[common]
bind_port = 7000
vhost_https_port = 443

客户端配置:

# frpc.ini
[common]
server_addr = x.x.x.x
server_port = 7000

[test_https2http]
type = https
custom_domains = test.example.com

plugin = https2http
plugin_local_addr = 127.0.0.1:80
plugin_crt_path = ./server.crt
plugin_key_path = ./server.key
plugin_host_header_rewrite = 127.0.0.1
plugin_header_X-From-Where = frp

外网访问地址:https://test.example.com

关于如何配置plugin_host_header_rewrite:https://github.com/fatedier/frp/issues/2482

这个plugin_host_header_rewrite可能会出问题,需要多尝试不同的写法。

设置token

为了避免任意客户端都可以连上frp服务器,需要在服务器的common配置块中设置一个token,客户端同样需要在common配置块中填一个相同的token。

监控面板

服务器端配置文件里添加

[common]
dashboard_port = 7500
# dashboard's username and password are both optional
dashboard_user = admin
dashboard_pwd = admin
dashboard_tls_mode = true
dashboard_tls_cert_file = server.crt
dashboard_tls_key_file = server.key

访问地址:https://[server_addr]:7500

配置面板

服务器端配置

[common]
admin_addr = 127.0.0.1
admin_port = 7400
admin_user = admin
admin_pwd = admin

别人是怎么使用frp的

https://frps.cn/41.html

获取用户真实ip

https://www.v2ex.com/t/474820

如这个讨论帖所说,使用https协议时,想要获取用户的真实ip地址,需要在frps的服务端套一个nginx,并且内网的源站还需要打开proxy protocol支持。

proxy protocol

https://docs.nginx.com/nginx/admin-guide/load-balancer/using-proxy-protocol/

总之,用frp获取用户真实ip太麻烦了,需要改整个反向代理的架构,服务端要多套一层Nginx,而且群晖的webstation的nginx服务器会把vhost配置文件里添加的proxy protocol协议自动清除掉(因为webstation默认是只支持http和https的),所以就不再折腾frp了,尝试换用nps,看是否能解决这个获取客户端ip的问题。

nps

安装

https://ehang-io.github.io/nps/#/install

选择docker版本安装

客户端选用下面这个版本的docker,其他版本有问题装不了:

https://registry.hub.docker.com/r/snowdreamtech/npc/

直接安装:

https://juejin.cn/post/7035943279078146056

nps漏洞

https://jireh.xyz/articles/2022/08/10/1660122191957.html

https://github.com/carr0t2/nps-auth-bypass

解决办法:不要注释auth_key,并且把auth_key和auth_crypt_key都设置得复杂一点。

由此得出教训,在自己的私有项目/生产环境中使用这些开源代码需要谨慎。