20180303
localtunnel
自行搭建服務(wù)器的請繼續(xù)往下翻
簡介
由于 ipv4 地址的數(shù)量不足,大部分中國地區(qū)的家庭 ip 地址均是由 ISP 轉(zhuǎn)發(fā),無法實現(xiàn)搭建個人服務(wù)器的目標(biāo)。而如果采用 ddns 服務(wù)商如花生殼等,在價格昂貴的同時配置極為復(fù)雜且不穩(wěn)定。為解決這樣的問題,localtunnel 出現(xiàn)了。
localtunnel 是一個基于 nodejs 的內(nèi)網(wǎng)穿透工具。通過簡單的安裝可以實現(xiàn)將內(nèi)網(wǎng)里的設(shè)備的某個端口暴露在公網(wǎng)中以提供服務(wù)。
使用
預(yù)先要求
- nodejs
- npm
安裝
npm install -g localtunnel // 安裝 localtunnel client
運行
lt --port PORT_OF_YOUR_SERVICE // 創(chuàng)建一個請求到 localtunnel.me 來獲取一個 URL 指向你的服務(wù)
// 輸出:your url is: https://RANDOM.localtunnel.me
// Advanced
// 使用 subdomain 參數(shù)和 local-host 參數(shù)
lt --port PORT_OF_YOUR_SERVICE --subdomain test --local-host HOSTNAME
// 請求將 HOSTNAME:PORT_OF_YOUR_SERVICE 暴露在 test.localtunnel.me 上
注意事項??
-
localtunnel.me只適用于開發(fā)測試之類的活動,不適合搭載生產(chǎn)環(huán)境 (使用自己搭建的localltunnel-server服務(wù)端來負(fù)載生產(chǎn)環(huán)境) -
localtunnel.me服務(wù)器在國外,可能造成訪問緩慢(使用自己搭建的localltunnel-server服務(wù)端來避免)。
localtunnel-server
負(fù)責(zé) localtunnel 請求并建立鏈接
預(yù)先要求
- 一臺具有公網(wǎng) ip 的服務(wù)器
- 服務(wù)器需要開放 1000-65535 的 tcp 端口
- 一個頂級域名 (
localtunnel-servermaster branch 不支持子域名) - 將域名
example.com和*.example.com解析到你的服務(wù)器上
注意事項??
- 不支持子域名解析到服務(wù)器 (i.e. 不支持
sub.example.com作為你服務(wù)器的 URL) - 不支持子域名解析到服務(wù)器 (i.e. 不支持
sub.example.com作為你服務(wù)器的 URL) - 不支持子域名解析到服務(wù)器 (i.e. 不支持
sub.example.com作為你服務(wù)器的 URL)
使用
安裝與運行
# pick a place where the files will live
git clone git://github.com/defunctzombie/localtunnel-server.git
cd localtunnel-server
npm install
# server set to run on port 1234
bin/server --port 1234
client 端配置
// 鏈接時指定 --host 參數(shù)
lt --port PORT --host http://example.com:1234 --subdomain sub
// 輸出:your url is: http://sub.example.com:1234
Docker 支持
詳見
https://github.com/localtunnel/server/#deploy
https://github.com/localtunnel/nginx#nginx-for-localtunnel
https://github.com/localtunnel/nginx#local-testing
Naive子域名支持
目前只支持二級,不支持頂級
https://github.com/William-An/server