微信开发时,本地服务调试域名的问题,遂搭建ngrok,内网穿透。很久以前搭建的,现整理到博客里,方便以后查阅
1 | # ubuntu 16 |
ecs域名解析
1 | A记录 ngrok.frontjs.cc |
安装依赖
sudo apt-get install build-essential golang mercurial
1
2
3
4
5
6
7
8
9
10
11# 备注:阿里云上默认装的golang是1.6,编译出的文件在mac上报错,可采用源码编译安装golang
golang版本地址:`https://golang.org/dl/`
wget -c https://dl.google.com/go/go1.10.linux-amd64.tar.gz
tar -C /usr/local -zxvf go1.10.linux-amd64.tar.gz
# 配置环境变量
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' >> /etc/profile
source /etc/profile
下载源码
1 | git clone https://github.com/inconshreveable/ngrok.git ngrok |
生成并替换源码里默认的证书
1 | NGROK_DOMAIN="ngrok.frontjs.cc" |
编译包
1 | GOOS=linux GOARCH=amd64 make release-server release-client |
启动服务
1 | ./bin/ngrokd -tlsKey=server.key -tlsCrt=server.crt -domain="ngrok.frontjs.cc" -httpAddr=":7098" -httpsAddr=":7099" |
配置并启动客户端
1 | # vim ngrok.cfg |
nginx 转发配置
到这里没遇到问题,那么就可以通过http://test.ngrok.frontjs.cc:7098
来访问本地7001
端口的服务了,下面配置nginx来忽略端口号访问, 添加7098的vhost1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16server {
listen 80;
listen [::]:80;
server_name *.ngrok.frontjs.cc;
proxy_set_header "Host" $host:7098;
root /mnt/portal-cms;
index index.html index.htm;
location / {
proxy_pass_header Server;
proxy_pass http://127.0.0.1:7098;
proxy_redirect off;
}
}
重启nginx(service nginx restart)http://test.ngrok.frontjs.cc
访问本地7001端口服务
报错及解决方法
1 | 1. 26958 segmentation fault |