本次使用工具推薦使用FRP(官網(wǎng)推薦看github上的開源鏈接https://github.com/fatedier/frp)担神,下面是實(shí)戰(zhàn)內(nèi)容:
關(guān)于FRP的安裝鹦牛,自行g(shù)oogle,無非就是下載流炕,解壓而已的操作嘶摊,本次實(shí)驗(yàn)只是針對(duì)穿透到內(nèi)網(wǎng)集峦,方便外網(wǎng)訪問內(nèi)網(wǎng)http服務(wù)伏社,其他加密措施詳見官方文檔;
我使用的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)
機(jī)器環(huán)境為:服務(wù)器端(centos7.6)客戶端(Ubuntu 18.10)
第一步:有一臺(tái)阿里云主機(jī)(或騰訊云主機(jī)等)能夠有公網(wǎng)Ip塔淤;
第二步:有一個(gè)能夠使用的域名(已備案)可以解析到上述擁有公網(wǎng)IP主機(jī)上摘昌;
第三步(在具有公網(wǎng)ip的機(jī)器上FRP服務(wù)器端配置):
解壓到指定目錄:
vim frps.ini編輯內(nèi)容如下:
[common]
bind_port = 7000
#web reflect innet service
vhost_http_port = 7085
備注:
bind_port: 為frp監(jiān)聽服務(wù)器機(jī)器的端口
vhost_http_port :外網(wǎng)訪問通過該端口映射到內(nèi)網(wǎng)
第四步(解析域名到公網(wǎng)服務(wù)器):
例如我的域名是ruichar.com 解析時(shí)使用*.ruichar.com解析到公網(wǎng)機(jī)器1.2.3.4(注意一定是*開頭方便后續(xù)自定義子域名);
第五步(公網(wǎng)ip高蜂、nginx映射配置):
server {
listen 80;
server_name *.ruichar.com;
location / {
# 7085端口即為frp監(jiān)聽的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客戶端配置,內(nèi)網(wǎng)機(jī)器):
vim?frpc.ini
[common]
#frp服務(wù)器的地址端口配置
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服務(wù)配置
type = http
#內(nèi)網(wǎng)主機(jī)的端口
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
最后啟動(dòng):
服務(wù)端啟動(dòng):
? ? 控制臺(tái)啟動(dòng):./frps -c ./frps.ini
? ? 后臺(tái)啟動(dòng):nohup ./frps -c frps.ini >/dev/null 2>&1 &
客戶端啟動(dòng):
????控制臺(tái)啟動(dòng):./frpc -c ./frpc.ini
? ? 后臺(tái)啟動(dòng):nohup ./frpc -c frpc.ini >/dev/null 2>&1 &
其中:在外網(wǎng)直接訪問web01.ruichar.com聪黎,web02.ruichar.com,web03.ruichar.com
即(假設(shè)內(nèi)網(wǎng)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是自己定義的子域名备恤;以上就完成了內(nèi)網(wǎng)穿透的具體案例稿饰;其他的配置參考github:
再發(fā)一遍鏈接:https://github.com/fatedier/frp
啊锦秒,碼字不容易!休息下眼睛@@@