frp内网穿透
前言:
如今都已经9102年了,可是国内的云服务器价格却是让人望而止步,什么阿里云、腾讯云最低配的1C,1G,1M价格都已经到了80RMB一个月,啧啧啧..就这个配置安装个tomcat跑几个测试项目都吃不消。索性想把服务器迁移到本地来。想法很美好,现实很骨感,移动不提供公网IP,没办法通过路由防火墙进行端口转发,只能另寻他法,正好前段时间接触了FRP,想着利用FRP搭建一个本地的服务器,So,Just do it!
准备内容:
一台能够上网的服务器(这里选择的是搬瓦工的小鸡)
一个正常解析的域名
一个虚拟机
教程开始
一:搭建FRP服务
- 使用putty或者Xshell登陆的Linux
- 选择搭建脚本,如果服务器是国外的选择GitHub,国内的选择Aliyun
GitHub
- wget https://raw.githubusercontent.com/MvsCode/frp-onekey/master/install-frps.sh -O ./install-frps.sh
- chmod 700 ./install-frps.sh
- ./install-frps.sh install
Aliyun
- wget https://code.aliyun.com/MvsCode/frp-onekey/raw/master/install-frps.sh -O ./install-frps.sh
- chmod 700 ./install-frps.sh
- ./install-frps.sh install
- 出现以下页面,进入安装流程,选择源码下载地址(国内选阿里,国外选github)
- 输入frp服务端口(默认即可)
- 选择代理http端口(默认即可)
- 选择代理https端口(默认即可)
- 输入frp后台web端管理端口(默认即可)
- 输入frp后台web端登陆账户(默认即可)
- 管理密码,也可也选择默认,也可以自己重新输入
- 连接frp服务的token,请牢记
- 本服务器的外网IP,默认可以获取到
- 最大线程(默认即可)
- 输入日志等级,这些操作都可以默认,一路回车的。
- 日志最长保留时间
- 是否开启日志(enable是开启,disable是禁用)
- 选择tcp多连接,默认最好
- kcp服务,默认打开就好
- 确认无误后选择回车安装,ctrl + c取消
- 出现此内容代表安装成功,请将内容保存下来。这个很重要。
- 如果有朋友想要卸载可以使用过以下的命令
- ./install-frps.sh uninstall
选择Y卸载
按下回车进行卸载
- 更新同理
- ./install-frps.sh update
二:配置Nginx转发
一:打开nginx配置文件(此处使用的是宝塔,如果是纯nginx代码,也是同理)
二:监听需要转发的域名比如:xxx.frp.com
如下图所示
代码如下
- # 转发websocket需要的设置
- proxy_set_header X-Real_IP $remote_addr;
- proxy_set_header Host $host;
- proxy_set_header X_Forward_For $proxy_add_x_forwarded_for;
- proxy_http_version 1.1;
- proxy_set_header Upgrade $http_upgrade;
- proxy_set_header Connection 'upgrade';
- # 所有请求都转发
- location / {
- proxy_pass http://127.0.0.1:180/;#此处的180是设置的frp 80监听的端口
- }
三:本地Linux安装frp客户端
frp官方git:https://github.com/fatedier/frp
发布页:https://github.com/fatedier/frp/releases(包含了linux、windows、arm等平台)
一:进入安装目录(usr/local/)
- cd /usr/local
二:下载frp资源文件
- wget https://github.com/fatedier/frp/releases/download/v0.24.0/frp_0.24.0_linux_amd64.tar.gz
三:解压文件
- tar -xzvf frp_0.24.0_linux_amd64.tar.gz
四:配置frp客户端,编辑frpc.ini文件,此文件为客户端文件
- cd frp_0.24.0_linux_amd64
- vi frpc.ini
修改参照
- [common]
- server_addr = 107.148.253.80
- server_port = 5443
- token = XgZCUaKRSoce52v8P
- [web]
- type = http
- local_port = 80
- custom_domains = xxx.frp.com
server_addr:frp服务的ip
server_port:frp服务的端口
token:token值
type:转发类型
local_port:本地监听端口
custom_domains:转发域名
五:配置systemctl控制frp
创建frp.sercer文件
- vim /lib/systemd/system/frps.service
在此文件内添加内容
- [Unit]
- Description=frp service
- After=network.target syslog.target
- Wants=network.target
- [Service]
- Type=simple
- ExecStart=/usr/local/frp_0.24.0_linux_amd64/frpc -c /usr/local/ frp_0.24.0_linux_amd64/frpc.ini
- [Install]
- WantedBy=multi-user.target
ESC退出编辑
输入:wq回车即可保存
六:使用systemctl控制frp
启动
- sudo systemctl start frps
关闭
- sudo systemctl stop frps
查看日志
- sudo systemctl status frps
开机启动
- sudo systemctl enable frps
Enjoy~~~
本文地址:frp内网穿透