Spring boot运行在本地服务器,不想部署在云服务器上,如何才能让外界能够访问到该服务呢?
先说原理:我们发送访问请求时,Frp会通过给定的公网ip和域名,转发到本地服务器上来,形成外部访问效果。即通过自定义域名访问内网的 Web 服务。
在云服务器上下载好Frp,作为服务器端。修改 frps.ini 文件,设置监听 HTTP 请求端口为 8080(可以根据需要自行更改)。 // An highlighted block [common] bind_port = 7000 vhost_http_port = 8080 进入frp文件夹下,启动服务。 Windows: frps.exe -c frps.iniLinux:
./frps -c ./frps.ini 在本地服务器上同样下载frp,作为客户端。修改 frpc.ini 文件,假设 frps 所在的服务器的 IP 为 x.x.x.x,local_port 为本地机器上 Web 服务监听的端口, 绑定自定义域名为custom_domains。注意,server_addr中的ip地址已经和这里的域名进行了绑定。也就是说,这里的两个域名www.yourdomain.com和www.yourdomain2.com都可以被解析成 x.x.x.x。 // An highlighted block [common] server_addr = x.x.x.x server_port = 7000 [web] type = http local_port = 80 custom_domains = www.yourdomain.com [web2] type = http local_port = 8080 custom_domains = www.yourdomain2.com 进入frp文件夹下,启动服务。 Windows: frpc.exe -c frpc.iniLinux
./frpc -c ./frpc.ini 通过浏览器访问 http://www.yourdomain.com:8080即可访问到处于内网机器上 80 端口的服务,访问http://www.yourdomain2.com:8080则访问到内网机器上 8080 端口的服务。End~
