Ngrok inbuilt file server configuration through config file - ngrok

Ngrok servers a folder using inbuild server when we run the following in command line
ngrok http file://<path to file>
I am trying to configure more tunnels like ssh in the same machine using config files like
tunnels:
httpbin:
proto: http
file: "//<path to file>" ##THIS IS ERROR ##
demo:
proto: ssh
addr: 22
is does not seems to be possible to configure inbuild file sharing using a configuration file in ngrok. Or is there some way?

You try this steps:
https://dashboard.ngrok.com/get-started/your-authtoken and login
Terminal and run: ngrok authtoken token_id
result: Authtoken saved to configuration file: /home/user/.ngrok2/ngrok.yml
Terminal: ngrok http file:///home
Finish !
result: https://i.stack.imgur.com/FPZbP.png
ngrok doc: https://ngrok.com/docs

Actually just stumbled across it by accident. A bit of experimentation, and no guarantees that it will continue to work since it's not mentioned in the docs. Just use the file: protocol in the addr yaml option.
authtoken: <REDACTED>
tunnels:
dev2:
proto: http
addr: file:///some/path/just/like/command/line
hostname: my-great-subdomain.ngrok.io

Related

How to start all tunnels defined in ngrok.yaml PyNgrok

I have a custom config here is the sample:
log_level: info
region: ap
tunnels:
http:
addr: 5000
proto: http
ssh:
addr: 22
proto: tcp
I specify the config path on pyngrok but when I try to run ngrok.connect() only HTTP part is working and show on my ngrok dashboard, no ssh tunnel. When I try the ngrok binary provided by pyngrok:
ngrok start --all --config=/ngrok.yaml
It works! On my ngrok dashboard I have HTTP, HTTPS and TCP.
These commands do not map to each other, which is why they do not do the same thing. connect() calls ngrok start --none, so it starts the ngrok process and API with no tunnels running, then it starts a tunnel using the API with the params you've passed to connect(). To start multiple tunnels, just call connect() more than once with different params.
from pyngrok import ngrok
conf.get_default().region = "ap"
tunnel1 = ngrok.connect(addr=5000)
tunnel2 = ngrok.connect(addr=22, proto="tcp")
In the above example, the config file isn't even necessary. If you already have tunnel definitions in your config though, you can use them by just passing their name.
from pyngrok import ngrok
conf.get_default().config_path = "/ngrok.yml"
tunnel1 = ngrok.connect(name="http")
tunnel1 = ngrok.connect(name="tcp")
The docs, which have many examples of this and other usage, can be found here.

How to enable both http and https tunnels in ngrok?

The ngrok help doc says: line 3: Only HTTPS tunnels by default - ngrok agent HTTP tunnels by default will only open a single HTTPS endpoint for your upstream service instead of both an HTTP and HTTPS endpoint. To enable both, you will need to add --scheme http --scheme https to your ngrok agent command or configuration file.
I tried to update the configuration file, but no success. I got "ERROR: line 3: field schemes not found in type config.v2yamlConfig"
version: "2"
authtoken: faswETNh3FAW8DSmVuHrOH18s_6pK7iuqkQP5
schemes: http,https
I also tried the following. I got "ERROR: line 3: field scheme not found in type config.v2yamlConfig"
version: "2"
authtoken: faswETNh3FAW8DSmVuHrOH18s_6pK7iuqkQP5
scheme: http,https
The Ngrok version 3.0.0 has renamed bind_tls to schemes ngrok changelog:
changelog
Try this:
version: 2
authtoken: <TOKEN>
tunnels:
rails:
proto: http
addr: 5000
schemes: [https, http]
react:
proto: http
addr: 8080
schemes: [https, http]

Port-forwarding to a local domain using socat

I'm trying to setup port forwarding from localhost to a local server using socat. The server is available via http://my-local-domain.
Here is what I tried:
socat -d -d tcp-listen:8081,reuseaddr,fork tcp:my-local-domain:80
When I open the browser and go to http://localhost:8081, I see my original localhost page, not the page when I navigate to my-local-domain.
How does one create port-forwarding to a local domain using socat?
I found that I'm not able to use Port 80 because the Host appears as localhost to NGINX, and so localhost serves the request [which would explain the original issue].
You can verify this by:
Opening nginx.conf
Adding ..."Host=$host"... to the log_format
Tailing the access logs [tail -f /usr/local/nginx/logs/access.log]
You'll notice that Host is always localhost, and so localhost serves the request.
The way to solve this is to change the Host info from localhost to my-local-server:
Localhost:8081 --> [change Host info] --> my-local-server:80
The way I found to do this was to create a proxy via Node.JS [as a go-between] as follows:
Create proxy.js
Copy the contents of the code from this gist and paste into proxy.js
Run the following command in the terminal to create proxy to web server:
PORT_LISTEN=8091 PORT_TARGET=80 HOST_TARGET="my-local-server" HOST_ORIGIN="my-local-server" node proxy.js
Run socat to proxy
socat -d -d tcp-listen:8081,reuseaddr,fork tcp:localhost:8091
So now we have the following:
Localhost:8081 --> Localhost:8091 --> my-local-server:80
This is what worked.

How to use ngrok with hosts file (laradock)

I am using Laradock to develop locally and so have an entry in the hosts file.
How can I get this working with ngrok?
I tried:
ngrok http -host-header=site.test 80
(https://helgesverre.com/blog/expose-local-webserver/)
but get: Failed to complete tunnel connection
(site.test works)
I got this working by running ngrok on the host machine instead of the container.

ngrok not running due to proxy

I have ngrok installed on Ubuntu. I want to expose an application at 8080. The machine is behind a corporate proxy. I exported an environment variable http_proxy with the proxy value and tried to run the command:
./ngrok http 8080
The status remains reconnecting and the error says "Proxy Authorization required".
I have also tried it using a ngrok.yml config file with the proxy value. And specified the path of the file:
./ngrok http -config=./ngrok.yml 8080
This is how the config file looks:
console_ui: true
inspect_db_size: 50000000
log_level: debug
log_format: json
log: /var/log/ngrok.log
http_proxy: "http://username:password#proxyhost.co.in:8080"
tunnels:
jenkins:
addr: 8080
bind_tls: true
inspect: false
proto: http
Still the error persists. Inspite of specifying the correct proxy, its failing. Any help would be appreciated.
open CMD. And type this:
set http_proxy=
set https_proxy=
There should be the following entry:
authtoken: YOUR_NGROK_TOKEN
in the configuration file. Perhaps, due to its absence you get the error.
The token you can find from your ngrok-account, from dashboard.

Resources