frp入门使用记录
简介: frp 是一个专注于内网穿透的高性能的反向代理应用,支持 TCP、UDP、HTTP、HTTPS 等多种协议。可以将内网服务以安全、便捷的方式通过具有公网 IP 节点的中转暴露到公网
目前是因为没有公网ip 所以使用服务器的公网去映射
1. 安装
wget https://github.com/fatedier/frp/releases/download/v0.38.0/frp_0.38.0_linux_amd64.tar.gz
tar -xvf frp_0.38.0_linux_amd64.tar.gz
mkdir /usr/local/frp
mv frp_0.38.0_linux_amd64/* /usr/local/frp/
frps.ini: 服务端配置文件
frps: 服务端软件
frpc.ini: 客户端配置文件
frpc: 客户端软件
2. 配置systemctl来控制,服务端运行
vim /usr/lib/systemd/system/frp.service
- 写入以下内容,注意上文移动放置的路径和此处有关。这里是启动的服务端。
[Unit]
Description=The nginx HTTP and reverse proxy server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=simple
ExecStart=/usr/local/frp/frps -c /usr/local/frp/frps.ini
KillSignal=SIGQUIT
TimeoutStopSec=5
KillMode=process
PrivateTmp=true
StandardOutput=syslog
StandardError=inherit
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
- 现在就可以用 systemctl 套装来控制 frp 了。
- 启动/停止/重启,查看状态,设置开机自启/关闭开机自启
systemctl start frp
systemctl stop frp
systemctl restart frp
systemctl status frp
systemctl enable frp
systemctl disable frp
3. 配置和使用
3.1 服务端
frps.ini
[common]
bind_port = 7000
vhost_http_port = 80
token = 123
[ssh]
listen_port = 6000 是自己设定的ssh访问端口
[web]
type = http
custom_domains = test1.a.com
[web2]
示例
[common]
bind_port = 700
vhost_http_port = 9080
[ssh]
listen_port = 6000
[web]
type = http
custom_domains = onlylmf.cn
./frps -c ./frps.ini
nohup ./frps -c ./frps.ini &
netstat -auntp|grep 700
kill -9 xxxx

至此服务端就已经启动成功了!
3.2 客户端
因为我使用的是win10
所以直接下载 cmd运行了
https://github.com/fatedier/frp/releases
选择自己操作系统对应的版本进行下载

解压后 得到该目录

frpc.ini
[common]
server_addr = 远程frp服务器ip
server_port = 远程frp服务器端口
token = 远程frp服务器token
[http]
type = http
local_ip = 127.0.0.1
local_port = 本地端口号
remote_port = 远程frp服务器的http服务端口号
custom_domains = 自定义配置的域名
subdomain = 匹配服务端配置的subdomain_host
示例
[common]
server_addr = 121.41.12.64
server_port = 700
[web]
type = http
local_ip = 192.168.3.46
local_port = 80
custom_domains = szy.frp.onlylmf.cn
[web2]
type = http
local_ip = 192.168.0.166
local_port = 11180
custom_domains = tf.frp.onlylmf.cn
[lapis]
type = http
local_ip = 127.0.0.1
local_port = 11180
custom_domains = lapios.frp.onlylmf.cn
启动
./frpc -c ./frpc.ini
nohup ./frpc -c ./frpc.ini &

4. Nginx 配置
-
在域名网站 解析自定义域名后申请免费是ssl证书 下载crt和key放在服务器中 -
配置nginx配置 # 将访问80端口的网址 跳转到443
server{
listen 80;
server_name 需要跳转的网址;
add_header cettt $http_host; # 这里是自定义头
rewrite ^(.*)$ https://$http_host$1 permanent;
}
server {
listen 443 ssl;
server_name 需要转发的域名;
ssl_certificate 对应的ssl证书的crt.crt;
ssl_certificate_key 对应的ssl证书的key.key;
ssl_session_timeout 30m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
add_header ffff $http_host; # 这里是自定义头
location / {
proxy_redirect off;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:8090/;
}
}
5. 配置连接家里的路由器
纯属是我自己的需要而已
因为我租的房子网络没有公网ip 用不了DDNS 所以使用frp进行内网穿透
因为买的一个阿里云的服务器没怎么用 就把服务端放在服务器上 使用服务器的公网ip
- 先在服务器上安装frps
步骤如前面的步骤
下载安装后 配置frps.ini

我这边定义的 [web] 是我另外的穿透 现在使用的是 [Myrouter]
然后后台启动 服务端
- 在家里路由器上安装客户端
注: 因为我刷了openwrt的固件 所以下载frpc客户端 以及luci可视化的管理页面
? 可以在 软件包里搜索下载 frpc 、luci-app-frpc 、 语言包 luci-i18n0-frpc-zh-cn
? 如果搜索不到 就先下载到本地 然后在通过文件传输到 路由上

-
装好后 如果服务里没有显示 Frp内网穿透 那么可能是缓存引起的 登录路由器的ssh 把luci的缓存清空后 重启 rm /tmp/luci-indexcache
reboot
-
 在如果 都安装完成了 但一直frp显示未启动 那么可能是被禁止了 去系统的启动项去 找到frp 启动  然后不出意外的话应该就好了
- 进行全局和服务列表的配置

保存后 配置服务列表
点击添加后

至此就配置完成了
- 验证 在本地访问服务端的可视化界面查看

当时在frps.ini中配置了 dashboard_port 就是访问端口 还要记得在服务器的防火墙将设置的端口开放

- 设置 ssl 配置nginx 转发
-
前提是申请 对应的自定义域名的证书 下载crt和key 放入服务器中 -
配置nginx server {
listen 443 ssl;
server_name 需要跳转的域名;
ssl_certificate 申请的ssl的crt路径.crt;
ssl_certificate_key 申请的ssl的key路径.key;
ssl_session_timeout 30m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
add_header ffff $http_host; # 这里是自定义头
location / {
proxy_redirect off;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:9080/;
}
}
然后 访问自定义域名 则成功访问到转发网址
|