内网穿透-FRP实战

本次使用工具推荐使用FRP(官网推荐看github上的开源链接https://github.com/fatedier/frp),下面是实战内容:

关于FRP的安装,自行google,无非就是下载,解压而已的操作,本次实验只是针对穿透到内网,方便外网访问内网http服务,其他加密措施详见官方文档;

我使用的release版本为:frp_0.30.0_linux_amd64(https://github.com/fatedier/frp/releases/download/v0.30.0/frp_0.30.0_linux_amd64.tar.gz)

机器环境为:服务器端(centos7.6)客户端(Ubuntu 18.10)

第一步:有一台阿里云主机(或腾讯云主机等)能够有公网Ip;

第二步:有一个能够使用的域名(已备案)可以解析到上述拥有公网IP主机上;

第三步(在具有公网ip的机器上FRP服务器端配置):

解压到指定目录:

vim frps.ini编辑内容如下:

[common]

bind_port = 7000

#web reflect innet service

vhost_http_port = 7085

备注:

bind_port: 为frp监听服务器机器的端口

vhost_http_port :外网访问通过该端口映射到内网

第四步(解析域名到公网服务器):

例如我的域名是ruichar.com 解析时使用*.ruichar.com解析到公网机器1.2.3.4(注意一定是*开头方便后续自定义子域名);
阿里云域名解析设置

第五步(公网ip、nginx映射配置):

server {

listen 80;

server_name *.ruichar.com;

location / {

#7085端口即为frp监听的http端口

proxy_pass http://127.0.0.1:7085;

proxy_set_header Host $host:80;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_set_header Upgrade $http_upgrade;

proxy_set_header Connection "upgrade";

proxy_connect_timeout 7d;

proxy_send_timeout 7d;

proxy_read_timeout 7d;

}

#防止爬虫抓取

if ($http_user_agent ~* "360Spider|JikeSpider|Spider|spider|bot|Bot|2345Explorer|curl|wget|webZIP|qihoobot

|Baiduspider|Googlebot|Googlebot-Mobile|Googlebot-Image|Mediapartners-Google|Adsbot-Google

|Feedfetcher-Google|Yahoo! Slurp|Yahoo! Slurp China|YoudaoBot|Sosospider|Sogou spider

|Sogou web spider|MSNBot|ia_archiver|Tomato Bot|NSPlayer|bingbot")

{

return 403;

}

}

第六步(frp客户端配置,内网机器):

vim frpc.ini

[common]

#frp服务器的地址端口配置

server_addr = 1.2.3.4

server_port = 7000

[ssh]

type = tcp

local_ip = 127.0.0.1

local_port = 22

remote_port = 6000

[web01]

#http服务配置

type = http

#内网主机的端口

local_port = 8080

custom_domains = web01.ruichar.com

[web02]

type = http

local_port = 8081

custom_domains = web02.ruichar.com

[web03]

type = http

local_port = 8082

custom_domains = web03.ruichar.com

最后启动:

服务端启动

控制台启动:./frps -c ./frps.ini

后台启动:nohup ./frps -c frps.ini >/dev/null 2>&1 &

客户端启动:

控制台启动:./frpc -c ./frpc.ini

后台启动:nohup ./frpc -c frpc.ini >/dev/null 2>&1 &

其中:在外网直接访问web01.ruichar.com,web02.ruichar.com,web03.ruichar.com

即(假设内网ip为192.168.2.20) 访问:http://192.168.2.20:8080,http://192.168.2.20:8081,http://192.168.2.20:8082,

其中web01,web02,web03是自己定义的子域名;以上就完成了内网穿透的具体案例;其他的配置参考github:

再发一遍链接:https://github.com/fatedier/frp

啊,码字不容易!休息下眼睛@@@

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值