Ubuntu 16.04 编译Ngrok

其中用到域名ngrok.gl6.cc,将其解析到服务器
*.ngrok.gl6.cc 解析到ngrok.gl6.cc

apt-get install -y make gcc libc6-dev git wget
mkdir /usr/local
cd /usr/local
wget -c https://storage.googleapis.com/golang/go1.7.4.linux-amd64.tar.gz
tar -C /usr/local -zxvf go1.7.4.linux-amd64.tar.gz
cp -r /usr/local/go /usr/local/go-copy

echo 'export GOROOT=/usr/local/go' >> /etc/profile
echo 'export PATH=$PATH:$GOROOT/bin' >> /etc/profile
echo 'export GOPATH=$HOME/go' >> /etc/profile
echo 'export GOROOT_BOOTSTRAP=/usr/local/go-copy' >> /etc/profile
source /etc/profile

git clone https://github.com/inconshreveable/ngrok.git
export GOPATH=/usr/local/ngrok/
export NGROK_DOMAIN="ngrok.gl6.cc"
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 server.key 2048
openssl req -new -key server.key -subj "/CN=$NGROK_DOMAIN" -out server.csr
openssl x509 -req -in server.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out server.crt -days 5000

cp rootCA.pem assets/client/tls/ngrokroot.crt
cp server.crt assets/server/tls/snakeoil.crt
cp server.key assets/server/tls/snakeoil.key

#编译Linux客户端 服务器
cd /usr/local/go/src
GOOS=linux GOARCH=amd64 ./make.bash
cd /usr/local/ngrok/
GOOS=linux GOARCH=amd64 make release-server release-client

#编译Mac客户端
cd /usr/local/go/src
GOOS=darwin GOARCH=amd64 ./make.bash
cd /usr/local/ngrok/
GOOS=darwin GOARCH=amd64 make release-client

#编译Win客户端
cd /usr/local/go/src
GOOS=windows GOARCH=amd64 ./make.bash
cd /usr/local/ngrok/
GOOS=windows GOARCH=amd64 make release-client

启动服务器

#将命令加入/etc/rc.local实现开机自启
/usr/local/ngrok/bin/ngrokd -domain="ngrok.gl6.cc" -httpAddr=":80" -httpAddr=":443"

客户端连接

#创建配置文件 ngrok.cfg
server_addr: "ngrok.gl6.cc:4443"
trust_host_root_certs: false
tunnels:
    api:
        subdomain: "api"
        proto:
            http: 80
            https: 443
#运行
./ngrok -config=ngrok.cfg start api
Ubuntu 16.04 编译Ngrok_第1张图片
ngrok_test.png

你可能感兴趣的:(Ubuntu 16.04 编译Ngrok)