5

搭建ngrok服务(内网穿透)

 2 years ago
source link: http://wwj718.github.io/post/%E6%8A%80%E6%9C%AF/build-ngrok-server/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

搭建ngrok服务(内网穿透)

2015-09-09

由于众所周知的原因,我们无法使用ngrok.com

国内有一个基于ngrok的网络服务:tunnel.mobi,不过时常不稳定。所以想自己搭建一个

#搭建 环境:ubuntu14.04

#安装依赖
sudo apt-get install build-essential golang mercurial git`

#获取ngrok
git clone https://github.com/inconshreveable/ngrok.git ngrok
cd ngrok

#生成并替换默认的证书
NGROK_DOMAIN="YOUR_DOMAIN"
openssl genrsa -out base.key 2048
openssl req -new -x509 -nodes -key base.key -days 10000 -subj "/CN=$NGROK_DOMAIN" -out base.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 base.pem -CAkey base.key -CAcreateserial -days 10000 -out server.crt
cp base.pem assets/client/tls/ngrokroot.crt

#开始编译 sudo make release-server release-client

编译完成后bin目录下将生产ngrokd和ngrok


###编译window版本客户端: GOOS=windows GOARCH=386

sudo GOOS=windows GOARCH=386  make  release-client

###编译mac版本客户端:

sudo GOOS=darwin GOARCH=amd64 make  release-client

之后都能在bin目录下找到

#运行服务

chmod +x ./bin/ngrokd
sudo ./bin/ngrokd -tlsKey=server.key -tlsCrt=server.crt -domain="YOUR_DOMAIN" -httpAddr=":8000" -httpsAddr=":443"

#注意 客户端必须使用自己编译的ngrok文件

#设置开机自动启动ngrok服务 vim /etc/init.d/ngrok_start:

/path/to/ngrokd -tlsKey=/path/to/server.key -tlsCrt=/path/to/server.crt -domain="findhao.com" -httpAddr=":8000" -httpsAddr=":443"

做些设置:

sudo chmod 755 /etc/init.d/ngrok_start
cd /etc/init.d
sudo update-rc.d ngrok_start defaults 20
#卸载启动脚本
cd /etc/init.d
sudo update-rc.d -f ngrok_start remove

#设置域名解析 把域名解析到VPS上,如果你只需要主机记录@和www,直接设置A记录把他们解析到VPS的IP上,如果需要很多二级域名的话,可以直接把*解析到IP上

#客户端使用 vim ngrok.cfg:

server_addr: YOUR_DOMAIN:4443
trust_host_root_certs: false

./ngrok -subdomain wwj -config=ngrok.cfg 8000


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK