ngrok 內網穿透 服務器搭建(centos7)


1、 安裝git環境和go環境

yum -y install git
yum -y install golang

2、下載 ngrok 源碼

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

3、導入 ngrok 我們配置的域名

// 假設我們想要給 ngrok 配置的外網域名是:ngrok.demo.com
echo 'export NGROK_DOMAIN=ngrok.demo.com' >> ~/.bashrc
source ~/.bashrc

4、生成自簽名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 server.key 2048
openssl req -new -key server.key -subj "/CN=$NGROK_DOMAIN" -out server.csr
openssl x509 -req -in server.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out server.crt -days 5000
 
// 拷貝證書文件到指定位置 
cp rootCA.pem assets/client/tls/ngrokroot.crt
cp server.crt assets/server/tls/snakeoil.crt
cp server.key assets/server/tls/snakeoil.key

5、編譯安裝 ngrok 服務端,我們編譯64位 linux 版:

GOOS=linux GOARCH=amd64 make release-server

6、編譯安裝 ngrok 客戶端,我們編譯64位 mac 和 windows 版:

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

從服務器端下載編譯好的客戶端到本地:

scp root@xxx:~/ngrok/bin/darwin_amd64/ngork ./
scp root@xxx:~/ngrok/bin/windows_amd64/ngork.exe ./

7.啓動 ngrokd 服務

// 直接啓動
ngrokd -domain="$NGROK_DOMAIN" -httpAddr=":8001" -httpsAddr=":8002"

// 後臺啓動
nohup ngrokd -domain="$NGROK_DOMAIN" -httpAddr=":8001" -httpsAddr=":8002" &

8.客戶端連接

// 創建 ngrok.conf 配置文件,加入以下內容
server_addr: "ngrok.demo.com:4443"
trust_host_root_certs: false

// 啓動 ngrok 客戶端,8000 端口(所以我們需要在本地按端口來配置虛擬主機)
ngrok -config=./ngork.conf -subdomain=demo 8000
發佈了13 篇原創文章 · 獲贊 5 · 訪問量 3137
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章