1. 程式人生 > >自建ngrok server

自建ngrok server

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

 

 

NGROK_DOMAIN="han1"

openssl genrsa -out base.key 2048

openssl req -new -x509 -nodes -key base.key  -days 10000 -subj "/CN=$NGROK_DOMAIN" -out base.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 base.pem -CAkey base.key -CAcreateserial -days 10000 -out server.crt

cp base.pem assets/client/tls/ngrokroot.crt 
cp server.crt assets/server/tls/snakeoil.crt 
cp server.key assets/server/tls/snakeoil.key 

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

./bin/ngrokd -tlsKey=server.key -tlsCrt=server.crt -domain="han1" -httpAddr=":8080" -httpsAddr=":8081"

ftp  bin/windows_amd64 到

本地 Desktop\windows_amd64>

修改本地   hosts 檔案增加   遠端ip   han.han1

執行client 

ngrok -config=ngrok.cfg -log=ngrok.log -subdomain=han 80

 

http://han.han1:8080/index.html

 

http://127.0.0.1:4040/http/in

 

 [Unit]
Description=  ngrokd
After=syslog.target network.target
 
[Service]
PrivateTmp=true
Type=simple
Restart=always
RestartSec=1min
StandardOutput=null
StandardError=null
ExecStart=/root/ngrok/ngrok/bin/ngrokd -log /var/log/ngrokd/ngrokd.log -log-level ERROR -tlsKey=/root/ngrok/ngrok/server.key -tlsCrt=/root/ngrok/ngrok/server.crt -domain=han1 -httpAddr=:8080 -httpsAddr=:8081  %i
ExecStop=/usr/bin/killall ngrokd
 
[Install]
WantedBy=multi-user.target

將上面的指令儲存為ngrok.service並移動到  /usr/lib/systemd/system/

systemctl enable ngrok.service //加入開機啟動
systemctl daemon-reload  //重新載入 systemd,掃描新的或有變動的單元

window 本地的cfg檔案

server_addr: han1:4443
trust_host_root_certs: false
tunnels: 
    api:
        subdomain: "api"
        proto:
            http: 80
    t:
        subdomain: "t"
        proto:
            http: 80
    wx:
        subdomain: "wx"
        proto:
            http: 80
    m:
        subdomain: "m"
        proto:
            http: 80
    han:
        subdomain: "han"
        proto:
            http: 8080
    rdp:
        remote_port: 13389
        proto:
            tcp: 3389
    ssh:
        remote_port: 10022
        proto:
            tcp: 22       

ngrok -config=ngrok.cfg -log=ngrok.log start han m

ngrok

Tunnel Status                 online
Version                       1.7/1.7
Forwarding                    http://han.han1:8080 -> 127.0.0.1:8080
Forwarding                    http://m.han1:8080 -> 127.0.0.1:80
Web Interface                 127.0.0.1:4040
# Conn                        0
Avg Conn Time                 0.00ms