买了阿里云服务器,但云服务器配置不高。为了能部署对配置要求高的项目,就把家里闲置的旧电脑利用上,把服务部署在家里的电脑上,通过frp内网穿透,把服务暴露到公网之上。这样就访问了,至于访问速度就得看家里的网速和云服务器的网速上限了。

frp 是一个专注于内网穿透的高性能的反向代理应用,支持 TCP、UDP、HTTP、HTTPS 等多种协议。可以将内网服务以安全、便捷的方式通过具有公网 IP 节点的中转暴露到公网。有了内网穿透在外访问家里的电脑、NAS、树莓派、摄像头等网络设备或远程控制。

阿里云和家里的电脑安装的都是Centos系统

1、下载frp

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

2、解压frp

解压后只需要关注四个文件,将服务端文件上传到云服务器上,客户端文件上传到家里的电脑上。

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

3、配置frp

服务端

frps.ini

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

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

客户端

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

4、启动frp

./frpc -c ./frpc.ini

# 后台启动
nohup ./frpc -c ./frpc.ini &

5、将frp配置成服务

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

vim /usr/lib/systemd/system/frp.service

根据实际路径修改ExecStart路径

[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 start frp
systemctl stop frp
systemctl restart frp
systemctl status frp
systemctl enable frp
systemctl disable frp

By xbingo

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注