由於作開發不少程度須要不斷同步git服務器或者什麼來作一些外部對接的測試
每次更新都要push到遠端,並且有時候代碼還未必正式寫完,不只影響git提交不美觀,並且麻煩
因此ngrok的內網穿透就顯神威了!
網上有ngrok的國內服務了,不過有時候不穩定
下面跟我一塊兒來架設本身的ngrok服務吧node
如:阿里雲等雲服務器最好,不過阿里雲記得用備案域名哦linux
解析到雲服務器或vps的ip (如: myngrok.com)
由於如下測試啓動了子域名自動部署,須要域名作泛解析, CNAME填寫"*"解析到雲服務器的ipc++
yum -y install zlib-devel openssl-devel perl hg cpio expat-devel gettext-devel curl curl-devel perl-ExtUtils-MakeMaker hg wget gcc gcc-c++ git
//請下載合適本身的go語言包 我是centos 6.8 64位 因此選擇如下包 wget https://storage.googleapis.com/golang/go1.8.3.linux-amd64.tar.gz tar -C /usr/local -xzf go1.8.3.linux-amd64.tar.gz vim /etc/profile //添加如下內容: export PATH=$PATH:/usr/local/go/bin source /etc/profile //檢測是否安裝成功go go version
mkdir /ngrok cd /ngrok git clone https://github.com/inconshreveable/ngrok.git
cd /ngrok mkdir cert cd cert openssl genrsa -out rootCA.key 2048 openssl req -x509 -new -nodes -key rootCA.key -subj "/CN=myngork.com" -days 5000 -out rootCA.pem openssl genrsa -out device.key 2048 openssl req -new -key device.key -subj "/CN=myngork.com" -out device.csr openssl x509 -req -in device.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out device.crt -days 5000
yes|cp rootCA.pem /ngrok/ngrok/assets/client/tls/ngrokroot.crt yes|cp device.crt /ngrok/ngrok/assets/server/tls/snakeoil.crt yes|cp device.key /ngrok/ngrok/assets/server/tls/snakeoil.key
go env //查看環境 GOOS=linux GOARCH=amd64 make release-server
./bin/ngrokd -tlsKey="assets/server/tls/snakeoil.key" -tlsCrt="assets/server/tls/snakeoil.crt" -domain="myngrok.com" -httpAddr=":8081" -httpsAddr=":8082" -tunnelAddr=":8083" #參數說明: #-domain 訪問ngrok是所設置的服務地址生成證書時那個 #-httpAddr http協議端口 默認爲80 #-httpsAddr https協議端口 默認爲443 (可配置https證書) #-tunnelAddr 通道端口 默認4443
cd /ngrok/ngrok setsid ./bin/ngrokd -tlsKey="assets/server/tls/snakeoil.key" -tlsCrt="assets/server/tls/snakeoil.crt" -domain="myngrok" -httpAddr=":8081" -httpsAddr=":8082" -tunnelAddr=":8083"
GOOS=windows GOARCH=amd64 make release-client #編譯成功後會在ngrok/bin/下面生成一個windows_amd64目錄下面有ngrok.exe #Linux 平臺 32 位系統:GOOS=linux GOARCH=386 #Linux 平臺 64 位系統:GOOS=linux GOARCH=amd64 #Windows 平臺 32 位系統:GOOS=windows GOARCH=386 #Windows 平臺 64 位系統:GOOS=windows GOARCH=amd64 #MAC 平臺 32 位系統:GOOS=darwin GOARCH=386 #MAC 平臺 64 位系統:GOOS=darwin GOARCH=amd64 #ARM 平臺:GOOS=linux GOARCH=arm
server_addr: "myngrok.com:8083" trust_host_root_certs: false
ngrok -config=ngrok.cfg -subdomain=test 80 //出現如下內容表示成功連接: ngrok Tunnel Status online Version 1.7/1.7 Forwarding http://test.myngrok.com:8081 -> 127.0.0.1:80 Forwarding https://test.myngrok.com:8081 -> 127.0.0.1:80 Web Interface 127.0.0.1:4040 # Conn 0 Avg Conn Time 0.00ms
server_addr: "myngrok.com:8083" trust_host_root_certs: false tunnels: http: subdomain: "www" proto: http: "8081" https: subdomain: "www" proto: https: "8082" web: proto: http: "8050" tcp: proto: tcp: "8001" remote_port: 5555 ssh: remote_port: 2222 proto: tcp: "22"
ngrok -config=ngrok.cfg start web #啓動web服務 ngrok -config=ngrok.cfg start tcp #啓動tcp服務 ngrok -config=ngrok.cfg start web tcp #同時啓動兩個服務 ngrok -config=ngrok.cfg start-all #啓動全部服務 //出現如下內容表示成功連接: ngrok Tunnel Status online Version 1.7/1.7 Forwarding http://web.myngrok.com:8081 -> 127.0.0.1:8050 Forwarding tcp://myngrok.com:5555 -> 127.0.0.1:8001 Web Interface 127.0.0.1:4040 # Conn 0 Avg Conn Time 0.00ms
@echo OFF color 0a Title ngrok啓動 Mode con cols=109 lines=30 :START ECHO. Echo ========================================================================== ECHO. Echo ngrok啓動 ECHO. Echo 做者: https://segmentfault.com/u/object ECHO. Echo ========================================================================== Echo. echo. echo. :TUNNEL Echo 輸入須要啓動的域名前綴,如「test」 ,即分配給你的穿透域名爲:「test.myngrok.com」 ECHO. ECHO. ECHO. set /p clientid= 請輸入: echo. ngrok -config=ngrok.cfg -subdomain=%clientid% 80 PAUSE goto TUNNEL
沒什麼好總結,不過你們能夠多研究下ngrok客戶端命令行git
在編譯過程當中有可能出現以下狀況: github
問題1:golang
GOOS="" GOARCH="" go get github.com/jteeuwen/go-bindata/go-bindataweb
bin/go-bindata -nomemcopy -pkg=assets -tags=release \vim
-debug=false \ -o=src/ngrok/client/assets/assets_release.go \ assets/client/...
make: bin/go-bindata: Command not foundsegmentfault
make: * [client-assets] Error 127windows
解決方法:前往go安裝目錄的bin目錄下找到go-bindata,將他移動到ngrok/bin下 (沒有bin,可新建一個)
問題2: package code.google.com/p/log4go: Get https://code.google.com/p/log4go/source/checkout?repo=: dial tcp 216.58.197.110:443: i/o timeout 由於google被牆,若是服務器不在牆外或者沒有FQ則沒法訪問到code.google.com. 解決方法:在 ngrok/src/ngrok/log 目錄下找到 logger.go 文件,修改其中第4或5行的: log "code.google.com/p/log4go」爲 log "github.com/keepeye/log4go"
問題3: GOOS="" GOARCH="" go get github.com/jteeuwen/go-bindata/go-bindata # github.com/jteeuwen/go-bindata src/github.com/jteeuwen/go-bindata/toc.go:47: function ends without a return statement make: *** [bin/go-bindata] Error 2 解決辦法: https://github.com/inconshreveable/ngrok/issues/237