Categories
Sitecore

Expose local server ports to the Internet with ngrok

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.

So, what exactly I can do in the Sitecore context world?

  • Well, you might have a local demo, POC on your local laptop and what to share the URL to a potential/existing client.
  • Or you want to try a next.js app in the Sitecore JSS context that is hosted on a free account to Vercel and you want to consume data from your local Sitecore instance.
  • Or you want to use an external SEO tool that has to crawl your not-ready-launched website?
  • Or you want a colleague (that also works from home) to login to your Sitecore instance to help you with something in the backend.

So, there are plenty of reasons and use cases where ngrok might be needed/usefull.

Ngrok service has indeed paid plans, but a free plan too that includes:

  • HTTP/TCP tunnels on random URLs/ports
  • 1 online ngrok process
  • 4 tunnels / ngrok process
  • 40 connections / minute

Here is how to get started:

  1. Sign up for a free account at https://ngrok.com/
  2. Download and run ngrok.exe (Or use chocolatey)
  3. Connect local ngrok to your account. You will need to run ngrok.exe authtoken {Your token should be here}. The token is saved in ~/.ngrok2/ngrok.yml on your system, for later usages.
  4. Expose your local instance with command: ngrok.exe http -region=eu -host-header=rewrite http://yourLocalInstance
    1.  Where yourLocalInstance should be your local address that you are using
    2. -region parameter defines the region where the tunnel will be hosted. If you do not explicitly pick a region, your tunnel will be hosted in the default region, the United States. Here is the list of all supported locations.
    3. -host-header=rewrite parameter is used so that the Host header will be rewritten to match the hostname portion of the forwarding address, in our case http://yourLocalInstance
  5. You will get public address that could be shared and used by anyone, that already is https enabled
ngrok status command
Status from the start command
ngrok status
Status Page
ngrok inspect
Inspect Traffic and Replay Requests

You can read more about ngrok capabilities in their official documentation in here.

Advertisement

By Sebastian Tecsi

Sitecore MVP 2018-2021
Sitecore Architect

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.