内网穿透之Frp搭建
Frp 内网穿透
使用场景
可以通过公网访问自己本地的web服务
环境
centos 7
域名一个(一二级都行)
安装
服务端安装
frp下载地址:https://github.com/fatedier/frp/releases
# 下载
wget https://github.com/fatedier/frp/releases/download/v0.36.2/frp_0.36.2_linux_amd64.tar.gz
# 解压进入
tar -xvf frp_0.36.2_linux_amd64.tar.gz
cd frp_0.36.2_linux_amd64
# 以下是服务端需要用到的
frps frps_full.ini frps.ini LICENSE systemd
# 修改服务端配置文件
vi frps.ini
# 修改
[common]
bind_port = 7000
vhost_http_port = 6080 # 指定外网访问内网的端口
# 启动服务
./frps -c frps.ini
# 执行结果
[root@iz2zef3qlb8a6ep8z61ru8z frp_0.36.2_linux_amd64]# ./frps -c frps.ini
2021/03/24 09:36:33 [I] [root.go:200] frps uses config file: frps.ini
2021/03/24 09:36:33 [I] [service.go:192] frps tcp listen on 0.0.0.0:7000
2021/03/24 09:36:33 [I] [root.go:209] frps started successfully
2021/03/24 09:37:08 [I] [service.go:449] [b1264ac351a0097f] client login info: ip [127.0.0.1:56726] version [0.36.2] hostname [] os [linux] arch [amd64]
2021/03/24 09:37:08 [I] [tcp.go:63] [b1264ac351a0097f] [ssh] tcp proxy listen port [6000]
2021/03/24 09:37:08 [I] [control.go:446] [b1264ac351a0097f] new proxy [ssh] success
2021/03/24 09:39:37 [I] [control.go:309] [b1264ac351a0097f] control writer is closing
2021/03/24 09:39:37 [I] [proxy.go:87] [b1264ac351a0097f] [ssh] proxy closing
2021/03/24 09:39:37 [I] [proxy.go:159] [b1264ac351a0097f] [ssh] listener is closed
2021/03/24 09:39:37 [I] [control.go:384] [b1264ac351a0097f] client exit success
客户端安装(windows)
# 下载并解压https://github.com/fatedier/frp/releases/download/v0.36.2/frp_0.36.2_windows_amd64.zip
# 修改客户端配置文件 frpc.ini为以下
[common]
server_addr = 127.0.0.1 # 服务器ip
server_port = 7000 # 服务端配置文件frps.ini中的bind_port
[web]
type = http
local_port = 8081 # 本地服务端口
custom_domains = baidu.com # 自己的域名
# 启动(在cmd中执行)
./frpc -c frpc.ini
本地服务启动(采用的python flask)
# encoding:utf8
from flask import Flask
app = Flask(__name__)
@app.route('/')
def index():
return "hello world"
if __name__ == '__main__':
app.run(port=8081)
结果
# 访问 examples.com:6080 本地服务会返回
* Serving Flask app "test" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://127.0.0.1:8081/ (Press CTRL+C to quit)
127.0.0.1 - - [24/Mar/2021 09:57:12] "GET / HTTP/1.1" 200 -
本文来自博客园,作者:Jruing,转载请注明原文链接:https://www.cnblogs.com/jruing/p/14572375.html