首先安装依赖的Go语言包
yum install golang
然后从GITHUB下载源代码
mkdir -p ~/go/src/github.com/mamboer
cd ~/go/src/github.com/mamboer
git clone https://github.com/mamboer/ngrok.git
编译之前,先要生成服务端和客户端密钥。
openssl genrsa -out rootCA.key 2048
openssl req -x509 -new -nodes -key rootCA.key -subj "/CN=yourdomain.com" -days 5000 -out rootCA.pem
openssl genrsa -out device.key 2048
openssl req -new -key device.key -subj "/CN=yourdomain.com" -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
然后编译服务端程序
make release-server
编译Windows客户端程序
GOOS=windows GOARCH=amd64 make release-client
服务端执行命令
ngrokd -domain="yourdomain.com" -httpAddr=":8088" -httpsAddr=":8089"
[15:08:52 CST 2016/02/18] [INFO] (ngrok/log.(*PrefixLogger).Info:83) [registry] [tun] No affinity cache specified
[15:08:52 CST 2016/02/18] [INFO] (ngrok/log.(*PrefixLogger).Info:83) [metrics] Reporting every 30 seconds
[15:08:52 CST 2016/02/18] [INFO] (ngrok/log.Info:112) Listening for public http connections on [::]:8088
[15:08:52 CST 2016/02/18] [INFO] (ngrok/log.Info:112) Listening for public https connections on [::]:8089
[15:08:52 CST 2016/02/18] [INFO] (ngrok/log.Info:112) Listening for control and proxy connections on [::]:4443
为了让客户端连接,需要打开默认的4443以及上面你监听的两个8088,8089端口,当然这些个端口是可以改的
iptables -A INPUT -p tcp --dport 4443 -j ACCEPT
其他略
客户端,链接命令
ngrok.exe -config=ngrok.cfg start web
相关的客户端配置文件ngrok.cfg,上面的启动中的web就是配置文件里面配置的内容
server_addr: yourdomain.com:4443
trust_host_root_certs: false
tunnels:
web:
subdomain: "demo";
proto:
http: 127.0.0.1:8080
把本地的8080端口发布到公网上,结合我们的例子,也就是发布到了yourdomain.com:8088上了。