How to generate fixed url with ngrok
Asked Answered
T

10

115

I am working on Facebook messenger.

My Facebook app only accept one url for a webhook but ngrok is generating a new URL every time. Now I am unable to test my app because the webhook URL has changed.

Terisateriyaki answered 27/6, 2016 at 9:21 Comment(2)
UPDATE NOV 2018: See answer below with 39+ upvotes suggesting other services! https://mcmap.net/q/188082/-how-to-generate-fixed-url-with-ngrokWedge
Update AUG 2023: Starting today, all users can claim one static domain for free -> dashboard.ngrok.com/cloud-edge/domainsElectrograph
O
207

UPDATE May 2020

Serveo is up and running again! No installation, no signup!

All you need to do is to run this:

ssh -R <unique subdomain>:80:<your local host>:<your local port> serveo.net

like

ssh -R youruniquesubdomain:80:localhost:8000 serveo.net

UPDATE January 2020

Since there are some issues with Serveo and localtunnel, I want to share with you another free ssh-based self-hosting service: Localhost.run

Unfortunately, it does not provide unique subdomains but it is ssh-based so you do not have to install additional applications. Still waiting for Serveo coming back.


UPDATE April 2018

I've found Serveo just now! And it is totally incredible!


UPDATE November 2017

Probably, it is not the best option for you but I started using localtunnel instead of ngrok.

An installation and run flow is very simple:

npm install -g localtunnel
lt --port <your localhost port> --subdomain youruniquesubdomain

Then I can go to my http://youruniquesubdomain.localtunnel.me That's it!

Orchard answered 26/11, 2017 at 19:53 Comment(25)
As I develop within a docker container, my virtual network runs off a subdomain.localhost URL. This tool does exactly what I needed. Thanks for the suggestion.Wilie
@Wilie I've updated my answer just now. Serveo looks extremely incredible!Orchard
Though it seems like a great service. Serveo doesn't actually work for my needs. I'm not sure if it's because my local env is being served from within a docker container or something but local tunnel seems to be able to handle it.Wilie
"Invalid host header" when serving my angular app. All well when serving a separate app... hmmNeff
Serveo is great! If you are looking for alternatives, there is also Burrow.io. You create and manage tunnels via web interface, so you don't even need to type ssh commands. Just paste a CURL command and BAM, tunnel opened.Alternation
@PauloArruda unfortunately it is not free :( But thank you for the info. it looks interestingOrchard
localchannel raise an error when you you define a subdomain: tunnel server offline: Request failed with status code 403Bikol
Automatically restart serveo after disconnect with until ssh -R aw2xcd:80:localhost:5000 serveo.net; do echo "Restarting..."; doneBlevins
Google Chrome detects serveo.net as dangerous. "Warning – visiting this website may harm your computer!".Exuberance
Servo is the best. The same URL every time you need. Better than ngrok. I strongly suggest to use it.Sixpence
Serveo ... wtf? Free? No install? No signup? Why do people make such amazingly amazing things and then give them to me for free? This just saved me $5/month from ngrok which I was happy to pay. THANK YOU STACK OVERFLOW.Molybdenous
wow !! just wow you can resuse your domain name again as well. ngrok sucks!!Puttergill
Hey, Serveo does sound awesome, but when I run the command just as indicated, I get this when going to the browser: Bad Request - Invalid Hostname, do you know what might be going on?Reconstitute
@MaximilianoAmbrosini probably that subdomain is occupied by someone else. I've just tried ssh -R youruniquesubdomaasdin:80:localhost:8000 serveo.net and it worked just fineOrchard
hmm I definitely used a unique subdomain, I'm not sure if it's related to it using https or something like that.Reconstitute
Looks promising. Can you set custom host-name header like with ngrok?Kaspar
localtunnel is throwing just 404 and serveo is down due issues with phishing by malicious usersKoa
@IvanCastellanos seems like ngrok hackers are trying to take their money back lolOrchard
@IvanCastellanos I have updated my answer. It is not good as Serveo but not bad as ngrok or localtunnel.Orchard
@Qumber This is why I use localhost.run. Serveo proved itself as convenient but highly unstableOrchard
@EugeneKovalev Well I've tried localhost.run but it does not give stable sub-domains for free. I found this another service called PageKite that lets you setup a subdomain and has a Pay What You Want pricing. Also it felt a bit faster to me.Urnfield
The Answer to "How to ...l with ngrok" is not "Install Serveo"Tammany
@Tammany you are always welcome to pay for ngrok billing plans. The link to the one is right below my answer, left by Arvind Pattar.Orchard
Localhost.run works really well 27.01.2022!Divert
Launched srv.us, which might or might not fare better. No account, no spyware (you'll have to trust that I run the code published…), subdomains are unique and persistent.Vershen
A
22

You need to set up auth token. You can find it here https://dashboard.ngrok.com/auth. (W̶o̶r̶k̶s̶ ̶w̶i̶t̶h̶ ̶f̶r̶e̶e̶ ̶v̶e̶r̶s̶i̶o̶n̶,̶ ̶n̶o̶ ̶n̶e̶e̶d̶ ̶t̶o̶ ̶p̶a̶y̶ it's now paid feature, see ngrok pricing).

Then you can use it like this:

ngrok http 80 --subdomain yoursubdomain
Arbil answered 26/9, 2016 at 13:4 Comment(8)
Doesn't works. Still the same error. Tunnel session failed: Only paid plans may bind custom subdomains. Failed to bind the custom subdomain 'mysubdomain' for the account 'Ck Maurya'. This account is on the 'Free' plan.Euchologion
That's really strange, I'm not paying a penny and I can use subdomain option. Maybe it's only working for some time on new accounts?Arbil
I'm having the same problem as @CkMaurya =(Carree
What version of ngrok you are using? I have ngrok version 2.0.19 installed, and when I run ngrok http 80 -subdomain yoursubdomain It works just fine. But as I said, token has to be set up. When I remove my token I'm getting same error. Maybe my account is somehow special, but I'm not paying for it.Arbil
@Arbil are you still able to access it freely?Decima
Version 2.2.8 gives ERR_NGROK_313 when running the above command with an authentication token in use.Vermiculate
Ngrok appears to have changed their pricing. Going to their pricing page shows that "custom subdomains" is a feature available starting on the "Basic" account level. ngrok.com/pricingStereophonic
Static Ngrok domains for free-plan users are available again -> ngrok.com/blog-post/free-static-domains-ngrok-usersHorrific
B
18

No more free subdomain support from ngrok.....pls have a error as below

Tunnel session failed: Only paid plans may bind custom subdomains. Failed to bind the custom subdomain 'arvindpattartestfb.ngrok.io' for the account 'arvccccc'. This account is on the 'Free' plan.

Upgrade to a paid plan at: https://dashboard.ngrok.com/billing/plan

ERR_NGROK_313

Baudekin answered 27/1, 2017 at 11:27 Comment(2)
Indeed. ngrok message: Tunnel session failed: Only paid plans may bind custom subdomains... Sign up at: https://ngrok.com/signup. If you have already signed up, make sure your authtoken is installed. Your authtoken is available on your dashboard: https://dashboard.ngrok.com.Zorine
when did this change and where was the announcement?Operator
K
9

Neither localtunnel.me or Serveo are working for me right now so I created a temporary solution that works for some use-cases including mine (react-native local development): using the ngrok npm package one can save the generated ngrok url into a json file, and that file can be read for any other app.

First make sure to install ngrok using npm install ngrok then use this node script:

const ngrok = require('ngrok');
const fs = require('fs').promises;

(async function() {
  const url = await ngrok.connect(3000);
  const api = ngrok.getApi();
  let data = await api.get('api/tunnels');
  data = JSON.parse(data);
  let dict = {'domain': data.tunnels[0].public_url}
  await fs.writeFile("config.json", JSON.stringify(dict));
  console.log("saved " + data.tunnels[0].public_url);
})();

Then from your app you may read it using code similar or equal to:

const backend = require('./config.json').domain;
Koa answered 4/1, 2020 at 1:6 Comment(2)
TypeError: api.get is not a functionHypostasis
use const tunnels = await api.listTunnels(); instead of api.get as its deprecatedHypostasis
P
4

For DHIS2 local installation, I did this on the terminal on ubuntu server.

Make sure your web is running on the specified port. Mine was on 8080.

ssh -R dani.serveo.net:80:localhost:8080 serveo.net

The beauty of this serveo.net is you can reuse the same hostname prefix url before serveo.net as many time as you want, even if power goes off or internet diconnection.

Puttergill answered 12/3, 2019 at 13:33 Comment(0)
P
3

Staqlab tunnel is providing domain for free. Its works great but need a binary to be downloaded from there website. Using this service for month without any hassle

Pyxie answered 18/10, 2020 at 19:10 Comment(0)
I
3

In 2022 (almost 2023) pagekite.me works for me. It is very similar to ngrok, and requires the installation of pagekite.py (and, obviously Python).

After installation click on pagekite.py opens pagekite shell.

Run command: 8080 subdomain.pagekite.me

Intracellular answered 24/12, 2022 at 19:51 Comment(1)
But it is not free, it's paid.Rete
L
2

I noticed that no one mentioned how to have static ngrok urls, which was the main question about.

A way to do it is to edit the ngrok.yml file, which is located at

Linux: "~/.config/ngrok/ngrok.yml"
MacOS (Darwin): "~/Library/Application Support/ngrok/ngrok.yml"
Windows: "%HOMEPATH%\AppData\Local\ngrok\ngrok.yml"

You can have content such as:

version: "2"
authtoken: valid_auth_token
tunnels:
  first-app:
    addr: 3000
    proto: http
    hostname: yourfixedngrok_id1.ngrok.io
  second-app:
    addr: 8000
    proto: http
    hostname: yourfixedngrok_id2.ngrok.io

This will help you expose multiple ports, and have a persisted url for each of which based on the value you set for hostnames.

After that, you run your ngrok using this command:

ngrok start --all
Luca answered 31/12, 2022 at 7:0 Comment(0)
S
2

Starting from August 2023, ngrok provides free static domains for everyone.

Related article

Quoting from the article above the steps to claim the domain are

  1. Log in to your ngrok account.
  2. Navigate to Cloud Edge > Domains.
  3. Follow the prompts to claim your unique, static domain.

Then you can use it by

ngrok http --domain=[static-domain] 80
Sweep answered 18/12, 2023 at 14:43 Comment(0)
S
0

Though its not a solution but take it as workaround, I had the same problem while testing. What i did is keep the ngrok running with my http port, so my ngrok url is not changing. but I frequently changing and restarting my server for testing and debugging.

Suprematism answered 30/5, 2017 at 7:11 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.