正確使用ngrok穿透內網
Expose a local web server to the internet
ngrok allows you to expose a web server running on your local machine to the internet. Just tell ngrok what port your web server is listening on.
If you don't know what port your web server is listening on, it's probably port 80, the default for HTTP.
Example: Expose a web server on port 80 of your local machine to the internet
ngrok http 80
When you start ngrok, it will display a UI in your terminal with the public URL of your tunnel and other status and metrics information about connections made over your tunnel.
The ngrok console UI
ngrok by @inconshreveable Tunnel Status online Version 2.0/2.0 Web Interface http://127.0.0.1:4040 Forwarding http://92832de0.ngrok.io -> localhost:80 Forwarding https://92832de0.ngrok.io -> localhost:80 Connnections ttl opn rt1 rt5 p50 p90 0 0 0.00 0.00 0.00 0.00
Inspecting your traffic
ngrok provides a real-time web UI where you can introspect all of the HTTP traffic running over your tunnels. After you've started ngrok, just open http://localhost:4040 in a web browser to inspect request details.
Try making a request to your public URL. After you have, look back at the inspection UI. You will see all of the details of the request and response including the time, duration, headers, query parameters and request payload as well as the raw bytes on the wire.
Detailed introspection of HTTP requests and responses
Replaying requests
Developing for webhooks issued by external APIs can often slow down your development cycle by requiring you do some work, like dialing a phone, to trigger the hook request. ngrok allows you to replay any request with a single click dramatically speeding up your iteration cycle. Click the Replay button at the top-right corner of any request on the web inspection UI to replay it.
Replay any request against your tunneled web server with one click
Request body validation
ngrok has special support for the most common data interchange formats in use on the web. Any XML or JSON data in request or response bodies is automatically pretty-printed for you and checked for syntax errors.
The location of a JSON syntax error is highlighted
Installing your Authtoken
Many advanced features of the ngrok.com service described in further sections require that you sign up for an account. Once you've signed
up, you need to configure ngrok with the authtoken that appears on your dashboard. This will grant you access to account-only features. ngrok has a simple 'authtoken' command to make this easy. Under the hood, all the authtoken command does is to add (or modify)
the authtoken
property in your ngrok
configuration file.
Install your authtoken
ngrok authtoken <YOUR_AUTHTOKEN>
HTTP Tunnels
Custom subdomain names
ngrok assigns random hexadecimal names to the HTTP tunnels it opens for you. This is okay for one-time personal uses. But if you're displaying the URL at a hackathon or integrating with a third-party webhook, it can be frustrating if the tunnel name changes
or is difficult to read. You can specify a custom subdomain for your tunnel URL with the -subdomain
switch.
Example: Open a tunnel with the subdomain 'inconshreveable'
ngrok http -subdomain=inconshreveable 80
ngrok by @inconshreveable
...
Forwarding http://inconshreveable.ngrok.com -> 127.0.0.1:80
Forwarding https://inconshreveable.ngrok.com -> 127.0.0.1:80
Password protecting your tunnel
Anyone who can guess your tunnel URL can access your local web server unless you protect it with a password. You can make your tunnels secure with the -auth
switch.
This enforces HTTP Basic Auth on all requests with the username and password you specify as an argument.
Example: Password-protect your tunnel
ngrok http -auth="username:password" 8080
Tunnels on custom domains (white label URLs)
Instead of your tunnel appearing as a subdomain of ngrok.io
,
you can run ngrok tunnels over your domains. To run a tunnel over dev.example.com
,
follow these steps:
- Enter
dev.example.com
as a Reserved Domain on your ngrok.com dashboard. This guarantees that no one else can hijack your domain name with their own tunnel. - On your dashboard, click on the 'CNAME' icon to copy your CNAME target.
- Create a DNS CNAME record from
dev.example.com
to your CNAME target. In this example, we would point the CNAME record toXXX.cname.ngrok.io
- Invoke ngrok with the
-hostname
switch and specify the name of your custom domain as an argument.Example: Run a tunnel over a custom domain
ngrok http -hostname=dev.example.com 8000
Disabling Inspection
ngrok records each HTTP request and response over your tunnels for inspection and replay. While this is really useful for development, when you're running ngrok on production services, you may wish to disable it for security and performance. Use the -inspect
switch
to disable inspection on your tunnel.
Example: An http tunnel with no inspection
ngrok http -inspect=false 80
Rewriting the Host header
When forwarding to a local port, ngrok does not modify the tunneled HTTP requests at all, they are copied to your server byte-for-byte as they are received. Some application servers like WAMP, MAMP and pow use theHost
header
for determining which development site to display. For this reason, ngrok can rewrite your requests with a modified Host header. Use the -host-header
switch
to rewrite incoming HTTP requests.
If rewrite
is specified, the Host
header
will be rewritten to match the hostname portion of the forwarding address. Any other value will cause the Host
header
to be rewritten to that value.
Rewrite the Host header to 'site.dev'
ngrok http -host-header=rewrite site.dev:80
Rewrite the Host header to 'example.com'
ngrok http -host-header=example.com 80
Tunneling only HTTP or HTTPS
By default, when ngrok runs an HTTP tunnel, it opens endpoints for both HTTP and HTTPS traffic. If you wish to only forward HTTP or HTTPS traffic, but not both, you can toggle this behavior with the -bind-tls
switch.
Example: Only listen on an HTTP tunnel endpoint
ngrok http -bind-tls=false site.dev:80
Example: Only listen on an HTTPS tunnel endpoint
ngrok http -bind-tls=true site.dev:80
TLS Tunnels
HTTPS tunnels terminate all TLS (SSL) traffic at the ngrok.com servers using ngrok.com certificates. For production-grade services, you'll want your tunneled traffic to be encrypted with your own TLS key and certificate. ngrok makes this extraordinarily easy with TLS tunnels.
Forward TLS traffic to a local HTTPS server on port 443
ngrok tls -subdomain=encrypted 443
Once your tunnel is running, try accessing it with curl.
curl --insecure https://encrypted.ngrok.io
TLS Tunnels without certificate warnings
Notice that --insecure
option in
the previous curl
command example?
You need to specify that because your local HTTPS server doesn't have the TLS key and certificate necessary to terminate traffic for anyngrok.io
subdomains.
If you try to load up that page in a web browser, you'll notice that it tells you the page could be insecure because the certificate does not match.
If you want your certificates to match and be protected from man-in-the-middle attacks, you need two things. First, you'll need to buy an SSL (TLS) certificate for a domain name that you own and configure your local web server to use that certificate and its
private key to terminate TLS connections. How to do this is specific to your web server and SSL certificate provider and beyond the scope of this documentation. For the sake of example, we'll assume that you were issued an SSL certificate for the domain secure.example.com
.
Once you have your key and certificate and have installed them properly, it's now time to run a a TLS tunnel on your own custom domain name. The instructions to set this up are identical to those described in the HTTP tunnels section: Tunnels
on custom domains. The custom domain you register should be the same as the one in your SSL certificate (secure.example.com
).
After you've set up the custom domain, use the -hostname
argument
to start the TLS tunnel on your own domain.
Forward TLS traffic over your own custom domain
ngrok tls -hostname=secure.example.com 443
Terminating TLS connections
It's possible that the service you're trying to expose may not have the capability to terminate TLS connections. The ngrok client can do this for you so that you can encrypt your traffic end-to-end but not have to worry about whether the local service has TLS
support. Specify both the -crt
and -key
command
line options to specify the filesystem paths to your TLS certificate and key and the ngrok client will take care of terminating TLS connections for you.
Offload TLS Termination to the ngrok client
ngrok tls -hostname secure.example.com -key /path/to/tls.key -crt /path/to/tls.crt 80
Running non-HTTP services over TLS tunnels
ngrok TLS tunnels make no assumptions about the underlying protocol being transported. All examples in this documentation use HTTPS because it is the most common use case, but you can run run any TLS-wrapped protocol over a TLS tunnel (e.g. imaps, smtps, sips, etc) without any changes.
Compatible Clients
TLS tunnels work by inspecting the data present in the Server Name Information (SNI) extension on incoming TLS connections. Not all clients that initiate TLS connections support setting the SNI extension data. These clients will not work properly with ngrok's TLS tunnels. Fortunately, nearly all modern browsers use SNI. Some modern software libraries do not though. The following list of clients do not support SNI and will not work with TLS tunnels:
- Microsoft Internet Explorer 6.0
- Microsoft Internet Explorer 7 & 8 on Windows XP or earlier
- Native browser on Android 2.X
- Java <=1.6
TCP Tunnels
Not all services you wish to expose are HTTP or TLS based. ngrok TCP tunnels allow you to expose any networked service that runs over TCP. This is commonly used to expose SSH, game servers, databases and more. Starting a TCP tunnel is easy.
Expose a TCP based service running on port 1234
ngrok tcp 1234
Examples
Expose an SSH server listening on the default port
ngrok tcp 22
Expose a Postgres server listening on the default port
ngrok tcp 5432
Expose a Minecraft server listening on the default port
ngrok tcp 25565
Listening on a reserved remote address
Normally, the remote address and port is assigned randomly each time you start a TCP tunnel. For production services (and convenience) you often want a stable, guaranteed remote address. To do this, first, log in to your ngrok.com dashboard and click "Reserve
Address" in the "Reserved TCP Addresses" section. Then use the-remote-addr
option
when invoking ngrok to bind a tunnel on your reserved TCP address.
Bind a TCP tunnel on a reserved remote address
ngrok tcp --remote-addr 1.tcp.ngrok.io:20301 22
相關推薦
正確使用ngrok穿透內網
Expose a local web server to the internet ngrok allows you to expose a web server running on your local machine to the internet. Just t
ngrok穿透內網(內網有代理的情況)
從早上到現在,找了很多工具,但均不支援代理,後詢問了同事,配合Proxifier,問題就解決了 安裝Proxifier,開啟 點選配置檔案—代理伺服器,在裡面填好代理伺服器地址 點選配置檔案—代理規則,配置新的ngrok規則,localhost規則也可以看一下 新增成
如何用ngrok進行內網穿透
2.點選左側選單“隧道管理”——>“開通隧道”,進入頁面後點擊購買免費版,進入頁面進行如下操作:“隧道名稱”隨便填入資訊,這裡填入“xxxxxx”;“前置域名”填入xxxxx(如lybwechat);“本地埠”為127.0.0.1:8080(這個可以改,只要與tom
阿里雲搭建ngrok實現內網穿透
內網穿透想必是開發微信的同志所必須的,大部分人首先想到的是去網上找各種現成的吧,比如sunny-ngrok或者向日葵之類的,但是世界上沒有免費的午餐,免費的都是會崩的!!!下面我就來教大家怎麼用阿里雲和ngrok搭建一個內網穿透!!!! 1.準備工作: 要能實現內網穿透,
搭建自己的ngrok服務(內網穿透 使用簡單)
在國內開發微信公眾號、企業號以及做前端開發的朋友想必對ngrok都不陌生吧,就目前來看,ngrok可是最佳的在內網除錯微信服務的tunnel工 具。記得今年春節前,ngrok.com提供的服務還一切正常呢,但春節後似乎就一切不正常了。ngrok.com無法訪問,
基於ngrok的內網穿透,將內網對映到公網上
熟悉Java的都熟悉,tomcat作為一個本地伺服器,僅限於本地訪問或者區域網訪問,如果想讓 其他的人訪問,就必須將專案放到伺服器上面,這樣的前提是必須要有一臺伺服器,其實也可以用也給辦法將內網穿透到
MAC 下使用 ngrok 實現內網穿透
2. 解壓到指定目錄:$ unzip -n ngrok-stable-darwin-amd64.zip -d /tmp3. 進入到解壓後的 ngrok 所在路徑: $ cd /tmp4. 開啟服務:
樹莓派通過ngrok實現內網穿透
最近在折騰樹莓派,想要實現遠端對寢室內的監控和對部件的控制,即通過外網訪問本地樹莓派。自然而然想到使用內網穿透,百度了一下有花生殼和NATAPP之類的服務提供商。不過這種事情還是自己折騰有意思,而且手頭也有一個沒用的域名和兩臺VPS,就決定自己來做了。
利用ngrok實現內網穿透
實現內網穿透紫ngrok無法通過天牆之後,國內也出現了一批成熟的商業化實現方案,諸如花生殼、net123、Sunny-ngrok等。不過免費的極不穩定還有流量頻寬限制,最後還是決定自己搭一個。本文利用ngrok搭建一個用於內網穿透的環境。需求是通過一
FTP搭建 共享上網 穿透內網外網
公網 消息 穿透內網 和數 了吧 5.1 需要 某某 初始化 1、ftp原理介紹 FTP只通過TCP連接,沒有用於FTP的UDP組件.FTP不同於其他服務的是它使用了兩個端口, 一個數據端口和一個命令端口(或稱為控制端口)。通常21端口是命令端口,20端口是數據端口。當混
reGeorg+proxifier穿透內網
reGeorg+proxifier穿透內網 前言 最近在實戰練習,一些複雜的網路環境或者配置總是讓人很頭疼,我也在解決問題的過程中遇到了這兩個工具,可以用來穿透內網,還是挺好用的。 step1 下載reGeorg與proxifier reGeorg:
自建ngrok實現內網埠對映
本文轉自:自搭Ngrok實現樹莓派內網穿透,有刪改。 如果把花生殼類比為使用別人搭好的ss服務,那麼自建Ngrok就是使用自己的ss服務,可見自搭Ngrok的優勢不言而喻,流量費用十分經濟,速度,穩定性和安全性將遠遠勝過花生殼。 現在花生殼是一種比較流行的穿透內網的方式,不過其穩定
穿透內網,連線動態ip,內網ip打洞-----p2p實現原理
轉自:http://www.cnblogs.com/eyye/archive/2012/10/23/2734807.html 網上找了很多,程式碼大堆,原理講清楚透徹的不多。 本人找幾篇講得好的來整理一下。 一片技術文章,最主要的講清楚原理,如果再有完整的能執行的原
使用ngrok將內網映射出去讓外網可以訪問的方法
一:軟體的下載ngrok的下載地址:https://pan.baidu.com/s/1maOHIznSbm-RVvV88bL87g 密碼:wfnk二:安裝的步驟1:賬號的註冊:https://www.ngrok.cc/ 1.1:點選註冊1.2:登入1.3:點選隧道管理1.4
穿透內網所瞭解的一些知識
在計算機網路中,網路地址轉換(Network Address Translation),是一種在IP封包通過路由器或防火牆時重寫源IP地址或目的IP地址的技術。這種技術被普遍使用在有多臺主機但只通過一個公有IP地址訪問因特網的私有網路中。簡單來講,NAT是將IP 資料包頭中的IP地址轉換為另一個IP地址的過
QQ通訊原理及QQ是怎麼穿透內網進行通訊的?
QQ是一個基於TCP/UDP協議的通訊軟體 傳送訊息的時候是UDP打洞,登陸的時候使用HTTP~因為登陸伺服器其實就是一個HTTP伺服器,只不過不是常用的那些,那個伺服器是騰訊自行開發的!!! 一、登入 QQ客戶端在區域網內,當你開啟QQ登入到QQ伺服器時,通過外網,你的客
SS 隧道穿透 內網 NAT
對應的情況這篇文章主要介紹瞭如何利用SSH 反向隧道穿透NAT,並演示瞭如何維持一條穩定的SSH 隧道。假設有機器A 和B,A 有公網IP,B 位於NAT 之後並無可用的埠轉發,現在想由A 主動向B 發起SSH 連線。由於B 在NAT 後端,無可用公網IP + 埠 這樣一個組
FtpServer穿透內網訪問配置踩筆記
FtpServer穿透內網訪問配置踩筆記 引言 FtpServer是伺服器檔案遠端管理常用方式。 以前在區域網配置Ftp伺服器以及使用公網上的Ftp服務均未碰到問題,固未對Ftp傳輸進行深入瞭解。 然而,最近在配置一臺內網Ftp伺服器提供外部訪問服務時,卻碰過了問題,折騰了幾番,方才搞定。為了避免遺忘和提供他
【本人禿頂程式設計師】內網穿透神器:Ngrok在支付中的正確使用姿勢
←←←←←←←←←←←← 我都禿頂了,還不點關注! 前言 隨著網際網路的發展,無論是web服務還是移動APP越來越多的都集成了第三方支付(支付寶、微信、銀聯)。通常作為服務提供方,支付成功以後都會有一個後端回撥URL來通知是否呼叫者是否支付成功,這個URL必須是公網環境,並且可以被訪
ngrok與花生殼的內網域名穿透
內網穿透內網穿透花生殼輸入https://b.oray.com/ 賬號xu-yi-zhong密碼進入管理界面,選擇內網穿透,如圖 點擊編輯,可以進行更改 ngrok輸入網址https://ngrok.cc/login登錄名[email protected]