CentOS7.4 搭建ngrok 内网穿透
生活随笔
收集整理的這篇文章主要介紹了
CentOS7.4 搭建ngrok 内网穿透
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
2019獨角獸企業重金招聘Python工程師標準>>>
#1、安裝git
# 安裝git yum install git#2、安裝GO語言環境
# 安裝GO語言環境 yum install golang #檢查下go的env環境變量 go env#3、下載ngrok
# github.com 下載 ngrok源碼 cd /usr/local/ git clone https://github.com/inconshreveable/ngrok.git#4、生成證書
# 域名xxx.com 換成自己的 cd /usr/local/ngrok openssl genrsa -out rootCA.key 2048 openssl req -x509 -new -nodes -key rootCA.key -subj "/CN=xxx.com" -days 5000 -out rootCA.pem openssl genrsa -out server.key 2048 openssl req -new -key server.key -subj "/CN=xxx.com" -out server.csr openssl x509 -req -in server.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out server.crt -days 5000#5、 拷貝證書覆蓋ngrok原來的證書
# 過程會讓你輸入y 回車 cp rootCA.pem assets/client/tls/ngrokroot.crt cp server.crt assets/server/tls/snakeoil.crt cp server.key assets/server/tls/snakeoil.key編譯生成服務端
# 編譯生成服務端 cd /usr/local/ngrok/ GOOS=linux GOARCH=amd64 make release-server編譯生成客戶端
# 32位linux客戶端: GOOS=linux GOARCH=386 make release-client# 64位linux客戶端: GOOS=linux GOARCH=amd64 make release-client#32位windows客戶端: GOOS=windows GOARCH=386 make release-client#64位windows客戶端: GOOS=windows GOARCH=amd64 make release-client#32位mac平臺客戶端: GOOS=darwin GOARCH=386 make release-client#64位mac平臺客戶端: GOOS=darwin GOARCH=amd64 make release-client#ARM平臺linux客戶端: GOOS=linux GOARCH=arm make release-client# 生成客戶端文件位置 /usr/local/ngrok/bin啟動服務器端
cd /usr/local/ngrok/bin./ngrokd -domain="xxx.com" -httpAddr=":800" -httpsAddr=":801" -tunnelAddr=":8443"# 指定TLS證書和密鑰 ./ngrokd -tlsKey="/path/to/tls.key" -tlsCrt="/path/to/tls.crt" -domain="xxx.com" -httpAddr=":800" -httpsAddr=":801" -tunnelAddr=":8443"客戶端配置文件ngrok.yml
# 新建ngrok.yml server_addr: xxx.com:8443 trust_host_root_certs: false本地啟動客戶端
# 目錄下打開命令行 # 然后使用以下任一命令運行ngrok: ngrok -config ngrok.yml 8080 ngrok -config ngrok.yml -subdomain wx 8080 # 或者指定域名 wx.xxx.comngrok 加入系統服務 開機啟動
vi /usr/lib/systemd/system/ngrok.service # 在CentOS 7上利用systemctl添加自定義系統服務 [Unit] Description=ngrok After=network.target[Service] Type=simple Restart=always RestartSec=1min ExecStart=/usr/local/ngrok/bin/ngrokd -domain=xqzgg.cn -httpAddr=:800 -httpsAddr=:801 -tunnelAddr=:8443 %i ExecStop=/usr/bin/killall ngrok PrivateTmp=true[Install] WantedBy=multi-user.target# 重載系統服務: systemctl daemon-reload# 設置開機啟動 systemctl enable ngrok.service# 啟動服務 systemctl start ngrok.service常用命令
#設置開機啟動: systemctl enable ngrok.service #啟動服務: systemctl start ngrok.service #停止服務: systemctl stop ngrok.service附帶一份 nginx.conf 配置文件
# ngrok upstream ngrok {server 127.0.0.1:800;keepalive 64; }# ngrok 穿透 server {listen 80;server_name *.xxx.com;location / {proxy_pass http://ngrok;proxy_redirect off;proxy_set_header Host $http_host:800;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; expires 5s;} }轉載于:https://my.oschina.net/u/3148025/blog/2874128
總結
以上是生活随笔為你收集整理的CentOS7.4 搭建ngrok 内网穿透的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 跨库多维分析后台的实现
- 下一篇: Axure之全局变量