实现安全的 web 代理--->添加口令保护
- 需求 安全地访问内网中的 web 主机,即实现 vps_ip:vps_port<-(frp)->soft_router<->web_host
- 在 frps.ini 添加
vhost_http_port = vps_port
- 在 frpc.ini 添加
[web]
type = http
local_ip = web_host_ip
local_port = web_host_port
custom_domains = vps_ip
http_user = your_user
http_pwd = your_pwd
实现多个应用的代理--->添加多个端口映射
- 需求 通过 vps 访问内网主机的多个应用
- 在 frpc.ini
[range:tcp_port]
添加
[range:tcp_port]
type = tcp
local_ip = 127.0.0.1
local_port = 6010-6020,6022,6024-6028
remote_port = 6010-6020,6022,6024-6028
use_encryption = false
use_compression = false
实现 frpc 长期稳定运行--->添加 daemon 守护进程
- 需求 监测 frpc 工作状态并复位修复
- 要求 frps 和 frpc 双方都开启安全的 web 代理
- 开发 watch_frpc.sh
#!/bin/sh
VPS_PORT=vhost_http_port
CONFIG_FILE=/etc/frp/frpc.d/frpc.ini
vps_ip=$(awk '$1=="server_addr" {print $3}' $CONFIG_FILE)
curl $vps_ip:$VPS_PORT | grep -q -w Unauthorized
if [ $? -eq 1 ]
then
echo "$(date '+%Y-%m-%d %H:%M:%S') [error]: frpc dropped,restart it!"
/etc/init.d/frpc restart
fi
- 将 watch_frpc.sh 添加到 crontab 中
* * * * * /watch_frpc.sh >> /watch_frpc.log
基于 openwrt 实现 daemon
- 安装 curl
opkg update
opkg install curl
- 开启 cron 服务
service cron start