内网穿透 - frp
使用 systemd
这个示例将会演示在 Linux 系统下使用 systemd 控制 frps 及配置开机自启。
在 Linux 系统下,使用systemd
可以方便地控制 frp 服务端 frps
的启动和停止、配置后台运行和开启自启。
要使用 systemd
来控制 frps
,需要先安装 systemd
,然后在 /etc/systemd/system
目录下创建一个 frps.service 文件。
如Linux服务端上没有安装
systemd
,可以使用yum
或apt
等命令安装systemd
。
# yum
yum install systemd
# apt
apt install systemd
使用文本编辑器,如
vim
创建并编辑frps.service
文件。
$ vim /etc/systemd/system/frps.service
# 重新加载
systemctl daemon-reload
写入内容
[Unit]
# 服务名称,可自定义
Description = frp server
After = network.target
Wants = network.target
[Service]
Type = simple
# 启动frps的命令,需修改为您的frps的安装路径
ExecStart = /path/to/frps -c /path/to/frps.toml
[Install]
WantedBy = multi-user.target
使用
systemd
命令,管理 frps。
# 启动frp
systemctl start frps
# 停止frp
systemctl stop frps
# 重启frp
systemctl restart frps
# 查看frp状态
systemctl status frps
配置 frps 开机自启。
systemctl enable frps
设备端配置systemd服务
frpc.service
[Unit]
# 服务名称,可自定义
Description = cfrpc server
After = network.target syslog.target
Wants = network.target
[Service]
Type = simple
# 记得修改此路径
ExecStart = /usr/local/bin/frpc -c /volume1/nas/frpc/frpc.toml
[Install]
WantedBy = multi-user.target
frps基础配置
# 服务监听端口
bindPort = 9700
# 监听IP
bindAddr = "0.0.0.0"
# web服务http端口 80端口已被其他应用占用 配置为8080
vhostHTTPPort = 8080
# web服务https端口
vhostHTTPSPort = 8443
# WEB访问域名绑定(绑定后只能绑定子域名访问)
subDomainHost = "frp.yang143.cn"
# 鉴权配置
auth.token = "***"
# web面板
webServer.port = 9080
# 面板用户名
webServer.user = "admin"
# 面板密码
webServer.password = "******"
log.to = "/root/frp/frps.log"
# trace, debug, info, warn, error
log.level = "info"
log.maxDays = 3
frpc配置示例
# 用户名,设置此参数后,代理名称会被修改为 {user}.{proxyName},避免代理名称和其他用户冲突。
user = "nas"
# frps公网IP
serverAddr = "*.*.*.*"
serverPort = 9700
# auth token
auth.token = "***"
# 日志文件地址
log.to = "/volume1/nas/frpc/logs.log"
# trace, debug, info, warn, error
log.level = "info"
log.maxDays = 3
# tcp协议穿透
[[proxies]]
name = "ssh"
type = "tcp"
localIP = "127.0.0.1"
localPort = 22
remotePort = 9222
# 限制带宽
transport.bandwidthLimit = "1MB"
[[proxies]]
name = "mysql"
type = "tcp"
localIP = "127.0.0.1"
localPort = 3306
remotePort = 9306
# http协议穿透
[[proxies]]
name = "nas"
type = "http"
localIP = "127.0.0.1"
localPort = 5000
subdomain = "nas"
[[proxies]]
name = "emby"
type = "http"
localIP = "127.0.0.1"
localPort = 8096
subdomain = "emby"
Nginx反向代理配置
frp web面板配置
配置域名 frp.yang143.cn
# 反向代理配置
location ^~ / {
proxy_pass http://127.0.0.1:9780;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Forwarded-Proto $scheme;
proxy_http_version 1.1;
add_header X-Cache $upstream_cache_status;
}
frp http访问配置
配置泛域名 *.frp.yang143.cn
# 反向代理配置
location ^~ / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Forwarded-Proto $scheme;
proxy_http_version 1.1;
add_header X-Cache $upstream_cache_status;
}
本文是原创文章,采用 CC BY-NC-ND 4.0 协议,完整转载请注明来自 Jonathan
评论
匿名评论
隐私政策
你无需删除空行,直接评论以获取最佳展示效果