首先安装GO环境,http://www.haiyun.me/archives/1009.html
1
2
3
4
|
cd
/usr/local/src/
git clone https:
//github
.com
/inconshreveable/ngrok
.git
export
GOPATH=
/usr/local/src/ngrok/
export
NGROK_DOMAIN=
"你的域名"
|
生成自签名SSL证书,ngrok为ssl加密连接:
1
2
3
4
5
6
7
8
9
10
11
12
|
cd
ngrok
openssl genrsa -out rootCA.key 2048
openssl req -x509 -new -nodes -key rootCA.key -subj
"/CN=$NGROK_DOMAIN"
-days 5000 -out rootCA.pem
openssl genrsa -out device.key 2048
openssl req -new -key device.key -subj
"/CN=$NGROK_DOMAIN"
-out device.csr
openssl x509 -req -
in
device.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out device.crt -days 5000
cp
rootCA.pem assets
/client/tls/ngrokroot
.crt
cp
device.crt assets
/server/tls/snakeoil
.crt
cp
device.key assets
/server/tls/snakeoil
.key
GOOS=linux GOARCH=386
make
clean
make
release-server release-client
|
如果一直停留在go get gopkg.in/yaml.v1参考:https://www.haiyun.me/archives/1011.html
将程序复制到/usr/local/bin以便可以直接使用
1
|
cp bin/ngrokd /usr/local/bin/ngrokd
|
启动SERVER:
ngrokd -tlsKey=assets/server/tls/snakeoil.key -tlsCrt=assets/server/tls/snakeoil.crt -domain="你的域名" -httpAddr=":8000" -httpsAddr=":8001" &
交叉编译windows客户端,最好安装最新版本Golang,使用yum安装的一直编译不通过,编译好在bin目录下。
1
2
3
4
|
cd
/usr/local/go/src/
GOOS=windows GOARCH=386 CGO_ENABLED=0 .
/make
.
bash
cd
-
GOOS=windows GOARCH=386
make
release-client
|
客户端配置(ngrok.cfg):
1
2
|
server_addr: "你的域名:4443"
trust_host_root_certs: false
|
Linux启动客户端:
1
|
bin
/ngrok
-config ngrok.conf start http
ssh
|
Windows启动客户端
1
|
ngrok -config="ngrok.cfg" -subdomain=test 8080
|
注意所有domain要一致,不然会出现证书错误:
1
|
Failed to read message: remote error: bad certificate
|