侧边栏壁纸
博主头像
峰峰火火

一条咸鱼罢了

  • 累计撰写 122 篇文章
  • 累计创建 89 个标签
  • 累计收到 59 条评论

目 录CONTENT

文章目录

FRP搭建内网穿透

峰峰火火
2022-09-27 / 1 评论 / 2 点赞 / 458 阅读 / 983 字 / 正在检测是否收录...
温馨提示:
若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

前言

工具下载-适用于Windows
已搭建好,直接下载工具修改配置文件, 点击start.bat
custom_domains 任选一个即可

修改ini配置文件

[common]
server_addr = 121.37.30.8
server_port = 6376
token = 41f1a553fd725468436eeac92425285f9accbd21e31325575ee27ab1ea928931
tls_enable = true
[web]
type = http
local_ip = 127.0.0.1
local_port = 80
custom_domains = proxy-1.fengzhengx.cn
custom_domains = proxy-2.fengzhengx.cn
custom_domains = proxy-3.fengzhengx.cn
custom_domains = proxy-4.fengzhengx.cn
custom_domains = proxy-5.fengzhengx.cn

vue 项目出现Invalid Host header解决办法

// vue.config.js文件中增加disableHostCheck属性
module.exports = {
  devServer: {
    disableHostCheck: true
  }
}

frp 是什么

frp 是一个专注于内网穿透的高性能的反向代理应用,支持 TCP、UDP、HTTP、HTTPS 等多种协议。可以将内网服务以安全、便捷的方式通过具有公网 IP 节点的中转暴露到公网。

有了内网穿透你能干什么?

远程访问内网的 http/https 服务
远程桌面(Windows/Mac)
远程文件、 SSH
小程序开发

安装

官方项目地址:https://github.com/fatedier/frp

以下命令请在服务器中执行
下载

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 

移动至/usr/local

mkdir /usr/local/frp
mv frp_0.38.0_linux_amd64/* /usr/local/frp/

文件说明

frps.ini: 服务端配置文件
frps: 服务端软件
frpc.ini: 客户端配置文件
frpc: 客户端软件

配置systemctl来控制,服务端运行

vim新建文件并写入配置内容

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

配置和使用

服务端

frps.ini

[common] #必须设置
bind_port = 7000 #是自己设定的frp服务端端口
vhost_http_port = 80 #是自己设定的http访问端口
token = 123  #核实身份用,加了更安全

[ssh] #ssh反向代理(不是必须设置)
listen_port = 6000 是自己设定的ssh访问端口

[web] #http反向代理[]里的内容可以自己设定,但是客户端和服务端必须要对应(如[aaa],[bbb]);
type = http #为服务类型,可以设为http,https
custom_domains = test1.a.com #为要映射的域名,记得域名的A记录要解析到外网主机的IP。

[web2] #同上(可设置多个)

示例

[common]
bind_port = 7000
vhost_http_port = 80

[ssh]
listen_port = 6000

[web]
type = http
custom_domains = test1.a.com

[web2]
type = http
custom_domains = test2.a.com

启动

./frps -c ./frps.ini

后台启动

nohup ./frps -c ./frps.ini &

客户端

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 = xx.xx.xx.xx
server_port = 7000
token = 123

[web] 
type = http
custom_domains = xx.xx.xx.xx
local_ip = 127.0.0.1
local_port = 8080
subdomain = k2p

启动

./frpc -c ./frpc.ini

后台启动

nohup ./frpc -c ./frpc.ini &

访问内网http/https服务

客户端配置

[common]
server_addr = FRP服务端IP
server_port = 7000
vhost_http_port = 80 #可自定义
vhost_https_port = 443 #可自定义
token= 123

[web] 
type = http
local_ip = 127.0.0.1
local_port = 8080
custom_domains = 自定义域名

运行服务后访问 custom_domains:vhost_http_port

更多配置参考 FRP 官网
文档

2

评论区