Problem processing
1. Failed to read valid http request: malformed HTTP request
[2019/05/07 17:11:36 CST] [DEBG] (ngrok/log.(*PrefixLogger).Debug:79) [ctl:12defafc] Waiting to read message [2019/05/07 17:11:46 CST] [DEBG] (ngrok/log.(*PrefixLogger).Debug:79) [ctl:12defafc] Closing [2019/05/07 17:11:46 CST] [EROR] (ngrok/log.Error:120) control recovering from failure EOFCopy the code
Server Logs
[09:11:23 UTC 2019/05/07] [WARN] (ngrok/log.(*PrefixLogger).Warn:87) [pub:662c9e97] Failed to read valid https request: malformed HTTP request "\ u007f \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 {\" Type \ ": \" Auth \ ", \ "content \" : {\ "Version \" : \ "2 \", \ "MmVersion \" : \ "1.7 \", \ "User \" : \ \ "" ,\"Password\":\"\",\"OS\":\"windows\",\"Arch\":\"amd64\",\"ClientId\":\"\"}}" [09:11:49 UTC 2019/05/07] [INFO] (ngrok/log.(*PrefixLogger).Info:83) [metrics] Reporting: {"bytesIn.count":0,"bytesOut.count":0,"connMeter.count":0,"connMeter.m1":0,"httpTunnelMeter.count":0,"linux":0,"osx":0," other":0,"tcpTunnelMeter.count":0,"tunnelMeter.count":0,"tunnelMeter.m1":0,"windows":0}Copy the code
CFG file and proxy connections on [::]:4443 port number.
[EROR] (Ngrok /log.Error:120) Control recovering from failure dial TCP: lookup ngrok.xxx.com on 100.8.8.8:100: no such host
If the DNS fails to be resolved, write the IP domain name to /etc/hosts
[EROR] (ngrok/log.Error:120) Control recovering from failure dial 52.194.135.42:4433: connectex: [EROR] (ngrok/log.Error:120) Control recovering from failure dial 52.194.135.42:4433: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
The corresponding port is not enabled, and the security group or firewall permits the port
… Failed to read message: remote error: Bad certificate……
Check that the ngrok. CFG file contains the same domain name as when you set up the certificate.
Check whether the system time of the client is the current year, month and day.
Set up the tutorial
Step 1: Install the GO build environment (Ngrok is developed for go)
1, download go:www.golangtc.com/download download and system corresponding to the version of your server. My system is CentOS 64-bit, I download go1.6rc2.linux-amd64.tar.gz
2. Decompress go to /usr/local/go
Ln -s /usr/local/go/bin/* /usr/bin/
Step 2: Download the ngrok source code
Bash
cd /usr/local/src/
git clone https://github.com/inconshreveable/ngrok.git
export GOPATH=/usr/local/src/ngrok/
export NGROK_DOMAIN="ngrok.zpblog.cn"
cd ngrok
Copy the code
Step 3: Generate a self-signed certificate
When using the official ngrok.com service, we use the official SSL certificate. To build our own NGROKD service, we need to generate our own certificate and provide an Ngrok client with that certificate.
Bash
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
cp rootCA.pem assets/client/tls/ngrokroot.crt
cp device.crt assets/server/tls/snakeoil.crt
cp device.key assets/server/tls/snakeoil.key
Copy the code
Step 4: Start compiling the server and client
1. Server
On the server side, it is easier to specify my environment variables and then make:
Bash
GOOS= Linux GOARCH=amd64 # if 32-bit system, here GOARCH=386Copy the code
And then make
Bash
make release-server
Copy the code
In theory, this should work, but I found that many dependencies need to be downloaded automatically when compiling. There is a package
Log4go will tell you that the package cannot be accessed, modify the source code, change the package to github address:
Find/usr/local/SRC/ngrok/SRC/ngrok/log/logger. Go, in the fifth line of the import log packages, changed to: the log “github.com/keepeye/log4go”
Then make release-server again
/usr/local/src/ngrok/bin = /usr/local/ SRC /ngrok/bin = /usr/local/ SRC /ngrok/bin = /usr/local/ SRC /ngrok/bin = /usr/local/ SRC /ngrok/bin = /usr/local/ SRC /ngrok/bin
Bash
bin/ngrokd -domain="$NGROK_DOMAIN" -httpAddr=":8000" -httpsAddr=":4433"
Copy the code
If no errors are reported, the following output appears:
Bash
[13:15:43 CST 2016/02/25] [INFO] (ngrok/log.(*PrefixLogger).Info:83) [registry] [tun] No affinity cache specified
[13:15:43 CST 2016/02/25] [INFO] (ngrok/log.(*PrefixLogger).Info:83) [metrics] Reporting every 30 seconds
[13:15:43 CST 2016/02/25] [INFO] (ngrok/log.Info:112) Listening for public http connections on [::]:8000
[13:15:43 CST 2016/02/25] [INFO] (ngrok/log.Info:112) Listening for public https connections on [::]:4433
[13:15:43 CST 2016/02/25] [INFO] (ngrok/log.Info:112) Listening for control and proxy connections on [::]:4443
Copy the code
CTRL + C to exit now, we still need to compile the client.
2. Client
1.1. Windows Client
GOOS=windows GOARCH=amd64 make release-client
cd /usr/local/go/src GOOS=windows GOARCH=amd64 ./make.bash cd - GOOS=windows GOARCH=amd64 make release-client This should generate an ngrok client in bin/windows_amd64Copy the code
1.2 raspberry PI client
CD /usr/local/go/src GOOS= Linux GOARCH=arm./make. Bash CD -goos = Linux GOARCH=arm make release-client # The ngrok client program is generated in the bin/ linux_ARM directoryCopy the code
1.3 MAC
GOOS=darwin GOARCH=amd64 make release-client
After the command is executed, the corresponding Windows and MAC directories are generated in the bin directory. Ngrok. exe is stored in the corresponding directories. Download the corresponding ngrok.exe file to the local PC.
Start the server ngrokd in the previous way, and the following prompts are displayed:
./bin/ngrokd -tlsKey=server.key -tlsCrt=server.crt -domain="xxx.xyz" -httpAddr=":80" -httpsAddr=":443"
Copy the code
Listening for public http connections on [::]:8000
Listening for public https connections on [::]:4433
Listening for control and proxy connections on [::]:4443
Remember these two ports 8000 and 4443.
8. Set the local client
(1) Create a configuration file ngrok.cfg in the same directory
server_addr: "xxx.xyz:4443"
trust_host_root_certs: false
Copy the code
Notice that port 4443 is used in the configuration file. (2) Create a startup script startup.bat in the same directory
@echo on
cd %cd%
#ngrok -proto=tcp 22
#ngrok start web
ngrok -config=ngrok.cfg -log=ngrok.log -subdomain=yjc 8080
Copy the code
-config indicates the configuration file, -log indicates the location where the log file is stored, and -subdomain indicates the user-defined domain name prefix. 8080 is the port number.
(3) To start, click startup script startup.bat or run CMD.
./ngrok -config=./ngrok.cfg -subdomain=test 80
Copy the code
Explain the parameters:
Bash
-config is the directory of the configuration file ngrok. CFG. -subdomain is the prefix to which the domain name needs to be assigned. 80 is the port on the local Websever, such as the port on which Apache listens.Copy the code
The following output appears:
Bash
Tunnel Status online Version 1.7/1.7 Forwarding http://test.ngrok.zpblog.cn:8000 - > 127.0.0.1:80 Forwarding https://test.ngrok.zpblog.cn:8000 - > 127.0.0.1:80 Web Interface 127.0.0.1:4040 # Conn 0 Avg Conn Time 0.00 msCopy the code