ngrok搭建(Windows服务端+Windows客户端)

1.go环境搭建(需要Linux系统)

1)下载源码,可以在http://www.golangtc.com/download

2)将其解压到/usr/local目录下:
tar -C /usr/local -xzf go1.9.2.linux-amd64.tar.gz

3).在root环境下执行如下命令:
mkdir $HOME/go
echo ‘export GOROOT=/usr/local/go’>> ~/.bashrc
echo ‘export GOPATH=$HOME/go’>> ~/.bashrc
echo ‘export PATH=$PATH:$GOROOT/bin’>> ~/.bashrc
source $HOME/.bashrc

4). 安装go get工具
yum install mercurial git bzr subversion

2.获取源码

git clone https://github.com/inconshreveable/ngrok.git

 

3. 编译
1). 配置环境变量

export NGROK_DOMAIN=”ngrok.example.com”

ngrok.example.com替换成你自己的域名。

 

2). 生成自签名ssl证书

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

4. 交叉编译生成windows客户端
上述编译过程生成的服务端和客户端都是linux下的,不能在windows下用。如果想编译生成windows客户端,需要重新配置环境并编译。 交叉编译过程如下:

进入go目录,进行环境配置
cd /usr/local/go/src/

GOOS=windows GOARCH=amd64 CGO_ENABLED=0 ./make.bash
进入ngrok目录重新编译
cd /usr/local/src/ngrok/

GOOS=windows GOARCH=amd64 make release-server release-client
编译后,就会在bin目录下生成windows_amd64目录,其中就包含着windows下运行的服务器和客户端程序。

 

此时会遇到错误

Set $GOROOT_BOOTSTRAP to a working Go tree >= Go 1.4.

解决办法是,下载golang1.4版本,然后执行下面命令。

 

tar zxvf [go1.4.2.darwin-amd64-osx10.8.tar.gz]
cp go/ $home/go-bootstrap/
GOROOT_BOOTSTRAP=$home/go-bootstrap/
export GOROOT_BOOTSTRAP

 

5.客户端及服务端配置。

以3389远程桌面为例。

客户端新建一个ngrok.cfg文件,内容如下:

server_addr: “ngrok.example.org:1180”
trust_host_root_certs: false

tunnels:
mstsc:
subdomain: “mstsc”
remote_port: 4443
proto:
tcp: “127.0.0.1:3389″

然后写一个批处理,内容如下:

ngrok -config=ngrok.cfg start mstsc

服务端也写一个批处理,内容如下:

ngrokd.exe -domain=”ngrok.example.org” -httpAddr=”:801″ -httpsAddr=”:802″ -tunnelAddr=”:1180″

 

6.参考

1.http://www.360doc.com/content/17/0524/18/29401987_656833431.shtml

2.https://www.jianshu.com/p/0146801c1178

3.https://www.jianshu.com/p/4f79ae4f081c

“ngrok搭建(Windows服务端+Windows客户端)”的4个回复

  1. Social networking sires including Facebook has generated a huge devote the web
    market. Target the Right Audience- According
    to your eeds target relevant age groups and demographics, and employ that language orr perhaps English.
    It is important to take proper precautions to protet your privacy on Facebook
    whilst your prkfile secured.

发表评论

电子邮件地址不会被公开。 必填项已用*标注

This site uses Akismet to reduce spam. Learn how your comment data is processed.