How to install ngrok

1 minute read

参考[https://www.svenbit.com/2014/09/run-ngrok-on-your-own-server/]

Ngrok的作用以及原理这里就不赘述了。详细介绍可以看维基百科

编译自己的Ngrok

系统:Ubuntu Ngrok版本

STEP1 build complie

sudo apt-get install build-essential

STEP2 install go language

     
sudo s apt-get install golang

STEP3 Ngrok relies on mercurial(version control)

    sudo apt-get install mercurial

STEP4 Clone ngrok’s github into your working directory

git clone https://github.com/inconshreveable/ngrok.git ngrok
cd ngrok

STEP5 create your own self-signed SSL certificate

    
NGROK_BASE_DOMAIN="ngrok.yourdomain.com"
openssl genrsa -out base.key 2048
openssl req -new -x509 -nodes -key base.key -days 10000 -subj "/CN=$NGROK_BASE_DOMAIN" -out base.pem
openssl genrsa -out server.key 2048
openssl req -new -key server.key -subj "/CN=$NGROK_BASE_DOMAIN" -out server.csr
openssl x509 -req -in server.csr -CA base.pem -CAkey base.key -CAcreateserial -days 10000 -out server.crt

Replace ngrok.yourdomain.com your domain,if you are planning to run your ngrok tunnels from *.ngrok.yourdomain.com subdomain,set the NGROK_BASE_DOMAIN to ngrok.yourdomain.com. And if you notice the following files will be generated as a result of the commands that we run earlier above:

    base.key
    base.pem
    base.srl
    server.crt
    server.csr
    server.key

yourdomain config

##STEP6 Copy your client certificate file

replace ngrok’s default client certificate file located at assets/client/tls/ngrokroot.crt with the one that you have just created:

    cp base.pem assets/client/tls/ngrokroot.crt

##STEP7 Now build/make the executable for both the server (release-server) and client (release-client),it may takes a while:

linux

GOOS=linux GOARCH=amd64 make release-server release-client GOOS=linux GOARCH=386 make release-server release-client

windows GOOS=windows GOARCH=amd64 make release-server release-client GOOS=windows GOARCH=386 make release-server release-client

##STEP8 Once it is done,the executable will be available inside /bin directory:

ngrok is the client executable and ngrokd is the server executable.You may need to make the file executable first by running the following command:

     chmod +X ngrokd
     chmod +X ngrok
 

And also,tabke note that the default executable generated is for Linux.

##STEP9 Running Ngrok Server

cp server.crt serverdir_with_ngrokd
cp server.jet serverdir_with_ngrokd

And then you can start ngrok server by running the following command(you may need root permission)

    ./ngrokd -tlsKey=server.key -tlsCrt=server.crt -domain="[NGROK_BASE_DOMAIN]" -httpAddr=":8080" -httpsAddr=":8081"

Test Open url http://yourdomain.com:8080

will see Tunnel yourdomain.com:8080 not found

##STEP10 RUnning Ngrok client

    vim ngrok.conf
erver_addr: "ngrok.yourdomain.com:4443"

trust_host_root_certs: false

tunnels:

  http:

    subdomain: "test"

    proto:

      http: "80"

  ssh:

    remote_port: 2222

    proto:

      tcp: "22"
ttp: "80"

run command

    ./ngrok -config=ngrok.conf start http ssh

ngrok.exe -subdomain testing -config=ngrok.cfg 80

ngrok.exe -subdomain testing -config=ngrok.cfg start http ssh

./ngrok -config=ngrok.conf start http ssh

Leave a Comment