这里以阿里云ECS为例,操作系统为CentOS7(64位)。
将一个域名或二级域名泛解析到VPS服务器上。 例如将*.ngrok.tanxin.link解析到VPS的IP。 要注意,此时还需要将ngrok.tanxin.link的A记录设置为VPS的IP。
- go的下载地址:http://www.golangtc.com/download
- git的下载地址:http://git-scm.com/downloads
- 绝对下载地址:https://www.kernel.org/pub/software/scm/git/git-2.6.0.tar.gz
- ngrok克隆地址:https://github.com/inconshreveable/ngrok.git
- 准备映射的域名:ngrok.tanxin.link
-
安装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++
-
下载git wget https://www.kernel.org/pub/software/scm/git/git-2.6.0.tar.gz
-
解压git tar zxvf git-2.6.0.tar.gz
-
编译git
cd git-2.6.0 ./configure --prefix=/usr/local/git make make install
-
创建git的软连接
ln -s /usr/local/git/bin/* /usr/bin
tar -zxvf go1.4.2.linux-amd64.tar.gz
mv go /usr/local/(*如果此处移动失败 请使用先复制到该目录再删除的方法)
-
go的命令需要做软连接到/usr/bin
ln -s /usr/local/go/bin/* /usr/bin
cd /usr/local/
git clone https://github.com/inconshreveable/ngrok.git
export GOPATH=/usr/local/ngrok/
export NGROK_DOMAIN="xxx.XXXX.xxx"(*此处改为你自己的域名即可)
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
按理来说,跳过这一步直接进行后续的编译工作没有什么问题。但是由于google无法访问,造成编译的时候从code.google.com上自动下载依赖包log4go超时而编译失败。
所以,我们需要将依赖包的下载地址改为github上的地址
vi /usr/local/ngrok/src/ngrok/log/logger.go
将第四行改成下面的
log "github.com/keepeye/log4go"
cd /usr/local/go/src
GOOS=linux GOARCH=amd64 ./make.bash
cd /usr/local/ngrok/
GOOS=linux GOARCH=amd64 make release-server
cd /usr/local/go/src
GOOS=darwin GOARCH=amd64 ./make.bash
cd /usr/local/ngrok/
GOOS=darwin GOARCH=amd64 make release-client
cd /usr/local/go/src
GOOS=windows GOARCH=amd64 ./make.bash
cd /usr/local/ngrok/
GOOS=windows GOARCH=amd64 make release-client
server_addr: "xxx.xxxx.xx:4443"
trust_host_root_certs: false
/usr/local/ngrok/bin/ngrokd -domain="$NGROK_DOMAIN" -httpAddr=":8888"
./ngrok -config=./ngrok.cfg -subdomain=blog 80
setsid ./ngrok -config=./ngrok.cfg -subdomain=test 80
screen -S yourname -> 新建一个叫yourname的session
screen -ls -> 列出当前所有的session
screen -r yourname -> 回到yourname这个session
screen -d yourname -> 远程detach某个session
screen -d -r yourname -> 结束当前session并回到yourname这个session
package code.google.com/p/log4go: exec: "hg": executable file not found in $PATH
yum install hg -y
fatal: Unable to find remote helper for 'https' 出现这个问题,可以重新安装 curl curl-devel 然后再重装git
wget https://www.kernel.org/pub/software/scm/git/git-core-0.99.6.tar.gz
tar zxvf git-core-0.99.6.tar.gz
cd git-core-0.99.6
make prefix=/usr/libexec/git-core install
export PATH=$PATH:/usr/libexec/git-core/
server
{
listen 80;
server_name *.ngrok.tanxin.com;
keepalive_timeout 70;
proxy_set_header "Host" $host:8888;
location / {
proxy_pass_header Server;
proxy_redirect off;
proxy_pass http://127.0.0.1:8888;
}
access_log off;
log_not_found off;
}
- 服务器防火墙 4443 端口开启
- golang注意版本
- ngrok nginx 端口竞争问题