使用frp做内网穿透,以达到外网访问内网的效果,便于远程操作。
一.安装frp
二.服务端配置(外网):
vi frps.ini
[common]
# 绑定的端口
bind_port = 7000
# 身份验证
token = xxxxxxxx
# vhost_http_port设置HTTP访问端口
vhost_http_port = 8080
# FRPS dashboard仪表盘登陆端口
dashboard_port = 7500
# FRPS 仪表盘用户名、密码
dashboard_user = admin
dashboard_pwd = admin
# subdomain_host自定义二级域名
# subdomain_host = xxx.com
# 指定Dashboard的监听地址
#dashboard_addr = 0.0.0.0
# 日志
log_file = ./frps.log
# 日志显示级别{debug, info, warn, error)
log_level = info
log_max_days = 3
# 服务端的subdomain_host需要和客户端配置文件中的subdomain、local_port配合使用
subdomain_host = dev.com
启动:
./frps -c frps.ini
三.客户端配置(内网):
vi frpc.ini
[common]
# x.x.x.x为ip或域名
server_addr = x.x.x.x
server_port = 7000
token = Spectator#0320
user=username
#FRPC 仪表盘
admin_addr = 127.0.0.1
admin_port = 7400
admin_user = admin
admin_pwd = admin
# [ssh]示例中 链接ssh 使用 root@x.x.x.x -p 6090
[ssh]
type = tcp
local_ip = 127.0.0.1
local_port = 22
remote_port = 6090
# [web] 示例中 访问本地web:x.x.x.x:8080 -> 127.0.0.1:8090(如果是域名,可以使用subdomain = sub,访问sub.x.x.x:8080 )
# remote_port对应frps.ini中的vhost_http_port
[web]
type = http
local_ip = 127.0.0.1
local_port = 8090
remote_port = 8080
custom_domains = x.x.x.x
启动:
./frpc -c frpc.ini
四.nginx代理
server {
listen 80;
server_name *.dev.com;
#charset koi8-r;
#access_log logs/host.access.log main;
set $domain "unexist";
if ($http_host ~* "^(.*)\.delpast\.com$") {
set $domain $1;
}
location /{
if ($domain = "sub") {
proxy_pass http://127.0.0.1:8080;
}
##不加以下内容代理任需要加端口
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Real-PORT $remote_port;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
注意:本文归作者所有,未经作者允许,不得转载