参考:
1、https://www.sunnyos.com/article-show-48.html
2、https://github.com/inconshreveable/ngrok/blob/master/docs/DEVELOPMENT.md
准备工作:
1、一台拥有公网ip的服务器或者vps
2、把需要做的主域名解析到服务器上面
软件下载地址:
go的下载地址:http://www.golangtc.com/download
git的下载地址:http://git-scm.com/downloads 各版本下载地址:https://www.kernel.org/pub/software/scm/git/
ngrok克隆地址:https://github.com/inconshreveable/ngrok.git
nginx安装地址参考:http://blog.csdn.net/dszgf5717/article/details/46850073
准备映射的域名:guaiwolo.win
二、安装Git
1、安装git,我安装的是2.6版本,防止会出现另一个错误,安装git所需要的依赖包
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++
2、
下载git
wget https://www.kernel.org/pub/software/scm/git/git-2.6.0.tar.gz
3、
解压git
tar zxvf git-2.6.0.tar.gz
4、编译git
cd git-2.6.0
./configure --prefix=/usr/local/git
make
make install
5、创建git的软连
ln -s /usr/local/git/bin/* /usr/bin/
三、
安装go环境
准备go环境,我的系统是64位的centos所以我下载amd64的包
1、到官网(https://www.golangtc.com/download)下载go软件包
wget http://www.golangtc.com/static/go/1.9.2/go1.9.2.linux-amd64.tar.gz
2、解压移到指定位置
tar -zxvf go1.9.2.linux-amd64.tar.gz
mv go /usr/local/
3、
go的命令需要做软连接到/usr/bin
ln -s /usr/local/go/bin/* /usr/bin/
4、检查是否安装正确
四、 编译ngrok1、下载ngrok,设置域名,ngrok地址
cd /usr/local/
git clone https://github.com/inconshreveable/ngrok.git
export GOPATH=/usr/local/ngrok/
export NGROK_DOMAIN="ngrok.guaiwolo.win"
cd ngrok
2、为域名生成证书
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
3、在软件源代码目录下面会生成一些证书文件,我们需要把这些文件拷贝到指定位置
cp rootCA.pem assets/client/tls/ngrokroot.crt
cp server.crt assets/server/tls/snakeoil.crt
cp server.key assets/server/tls/snakeoil.key
4、如果是在国内的服务器需要改下面文件,香港或者国外的服务器不需要,跳过这一步
vim /usr/local/ngrok/src/ngrok/log/logger.go
log "github.com/keepeye/log4go"
5、编译服务器
指定编译环境变量,如何确认GOOS和GOARCH,可以通过go env来查看
cd /usr/local/ngrok/
GOOS=linux GOARCH=amd64 make release-server
6、编译客户端
mac os 64位操作系统
cd /usr/local/ngrok/
GOOS=darwin GOARCH=amd64 make release-client
windows 32位系统
cd /usr/local/ngrok/
GOOS=windows GOARCH=386 make release-client
/usr/local/ngrok/bin
将此目录下的客户端(ngrok或ngrok.exe)拷贝出来即可
server_addr: ngrok.guaiwolo.win:4443
tunnels:
test:
proto:
http: 12345
启动(不通系统稍微有点不一样):
./ngrok -config=ngrok.yml -log=ngrok.log start test
systemctl stop firewalld