反向代理软件:ngrok1.7 (2.0后不开源了)
作用:通过搭建ngrok内网穿透服务器,可实现web服务器本地化,tcp、udp转发,简单来说就是可以让你的本地服务
暴露在外网上面,可以通过外网访问
环境:CentOS Linux release 7.4.1708 (Core)
一、域名解析
A记录 :ngrok.xfs.com.cn --x.x.x.x
泛解析 *.ngrok.xfs.com.cn -x.x.x.x
二、go环境搭建yum install go
三、安装git环境yum install git
四、获取ngrok源码
获取源码:git clone https://github.com/inconshreveable/ngrok.git
五、编译
cd
cd ngrok
export NGROK_DOMAIN="ngrok.xfs.com.cn"
2). 生成自签名ssl证书
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 device.key 2048
openssl req -new -key device.key -subj "/CN=$NGROK_DOMAIN" -out device.csr
openssl x509 -req -in device.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out device.crt -days 5000
3). 替换证书
\cp rootCA.pem assets/client/tls/ngrokroot.crt
\cp device.crt assets/server/tls/snakeoil.crt
\cp device.key assets/server/tls/snakeoil.key
4).设置变量:GOOS=linux GOARCH=amd64
32位系统, GOARCH=386
5).生成服务端和客户端make release-server release-client
编译之后,就会在ngrok源码的bin目录下生成两个可执行文件:ngrokd、ngrok。其中ngrokd就是ngrok的服务端程序,ngrok就是ngrok的客户端程序。
六、ngrokd服务启动与使用
1).启动ngrokd服务端
临时启动:
cd ngrok
bin/ngrokd -domain="ngrok.xfs.com.cn" -httpAddr=":80"
解析:
Usage of ./ngrokd:
-domain string
Domain where the tunnels are hosted (default "ngrok.com")
-httpAddr string
Public address for HTTP connections, empty string to disable (default ":80")
-httpsAddr string
Public address listening for HTTPS connections, emptry string to disable (default ":443")
-log string
Write log messages to this file. 'stdout' and 'none' have special meanings (default "stdout")
-log-level string
The level of messages to log. One of: DEBUG, INFO, WARNING, ERROR (default "DEBUG")
-tlsCrt string
Path to a TLS certificate file
-tlsKey string
Path to a TLS key file
-tunnelAddr string
Public address listening for ngrok client (default ":4443")
2).启动ngrokd客户端
创建ngrok.cfg配置文件
server_addr: "ngrok.xfs.com:4443"
trust_host_root_certs: false
客户端解析:
Options:
-authtoken string
Authentication token for identifying an ngrok.com account
-config string
Path to ngrok configuration file. (default: $HOME/.ngrok)
-hostname string
Request a custom hostname from the ngrok server. (HTTP only) (requires CNAME of your DNS)
-httpauth string
username:password HTTP basic auth creds protecting the public tunnel endpoint
-log string
Write log messages to this file. 'stdout' and 'none' have special meanings (default "none")
-log-level string
The level of messages to log. One of: DEBUG, INFO, WARNING, ERROR (default "DEBUG")
-proto string
The protocol of the traffic over the tunnel {'http', 'https', 'tcp'} (default: 'http+https') (default "http+https")
-subdomain string
Request a custom subdomain from the ngrok server. (HTTP only)
Examples:
ngrok 80
ngrok -subdomain=example 8080
ngrok -proto=tcp 22
ngrok -hostname="example.com" -httpauth="user:password" 10.0.0.1
Advanced usage: ngrok [OPTIONS] [command args] [...]
Commands:
ngrok start [tunnel] [...] Start tunnels by name from config file
ngork start-all Start all tunnels defined in config file
ngrok list List tunnel names from config file
ngrok help Print help
ngrok version Print ngrok version
Examples:
ngrok start www api blog pubsub
ngrok -log=stdout -config=ngrok.yml start ssh
ngrok start-all
ngrok version
客户端配置文件:
server_addr: "ngrok.xfs.com.cn:4443"
tunnels:
mstsc:
remote_port: 1494
proto:
tcp: ":1494"
web:
subdomain: citirx
proto:
http: ":8172"
windows批处理
cd %cd%
ngrok start mstsc citrix