启东的个人博客 - ngrok
type: channel
link: https://echo.solo90.com/tag/ngrok/
items: 安装ngrok服务器

安装ngrok服务器
type: item
date: 2018-10-17T12:07:00+00:00
description: 一、安装go环境yum install golang -y二、编译ngrokcd /usr/local/ git clone https://github.com/inconshreveable/ngrok.git export GOPATH=/usr/local/ngrok/ export NGROK_DOMAIN="域名" 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修改log下的logger.go go编译时会下载对应依赖项，如果依赖了code.google.com下的，你懂的。这里将ngrok/src/ngrok/log/logger.go中的第四行更改为“github.com/keepeye/log4go”，如果源码中已经是github的地址，那就不用更改了。五、编译服务端（根据自己系统的来）cd /usr/local/go/src GOOS=linux GOARCH=386 ./make.bash(32位) GOOS=linux GOARCH=amd64 ./make.bash(64位) cd /usr/local/ngrok/ GOOS=linux GOARCH=386 make release-server （32位） GOOS=linux GOARCH=amd64 make release-server（64位）六、编译客户端MAC OS 64位操作系统（32位系统把amd64改成386） cd /usr/local/go/src GOOS=darwin GOARCH=amd64 ./make.bash cd /usr/local/ngrok/ GOOS=darwin GOARCH=amd64 make release-client Windows 64位操作系统（32位系统把amd64改成386） cd /usr/local/go/src GOOS=windows GOARCH=amd64 ./make.bash cd /usr/local/ngrok/ GOOS=windows GOARCH=amd64 make release-client七、客户端配置文件默认端口号4443server_addr: "域名:4443" trust_host_root_certs: false八、服务器启动/usr/local/ngrok/bin/ngrokd -domain="ngrok.solo365.cn" -httpAddr=":801" -httpsAddr=":802"指定通信端口：-tunnelAddr=”:3389″九、客户端启动启动命令/usr/local/ngrok/bin/ngrok -log=./ngrok_log -config=./ngrok.cfg -subdomain=test 80十、配置nginx代理和服务器博客公用80端口做代理server { listen 80; server_name *.ngrok.solo365.cn; location / { proxy_pass http://127.0.0.1:801; proxy_redirect off; proxy_set_header Host $http_host:801; proxy_set_header X-Real-IP $remote_addr; proxy_connect_timeout 1; proxy_send_timeout 120; proxy_read_timeout 120; }…