ngrok

2020-12-16 hit count image

let's see how to access virtual machine(Guest System) from external environment by ngrok.

Outline

sometimes, we need to access virtual machine(Guest System) from external environment not local machine(Host System). at this time, if you use ngrok, you can access simply.

below link is the virtual machine(Guest System) for Laravel by Ansible to test ngrok.

the instruction of ngrok we’ll talk in there is for developing and testing.

Configure Ansible

the virtual machine(Gust System) in below link is

like below.

|-- ansible
|    |-- init
|    |    |-- tasks
|    |    |    |-- main.yml
|    |-- docker
|    |    |-- tasks
|    |    |    |-- main.yml
|    |-- laradock
|    |    |-- tasks
|    |    |    |-- main.yml
|    |-- php
|    |    |-- tasks
|    |    |    |-- main.yml
|-- Vagrantfile

we need to add role for ngrok, so create ansible/ngrok/taskas/main.yml file.

|-- ansible
|    |-- init
|    |    |-- tasks
|    |    |    |-- main.yml
|    |-- docker
|    |    |-- tasks
|    |    |    |-- main.yml
|    |-- laradock
|    |    |-- tasks
|    |    |    |-- main.yml
|    |-- php
|    |    |-- tasks
|    |    |    |-- main.yml
|    |-- ngrok
|    |    |-- tasks
|    |    |    |-- main.yml
|-- Vagrantfile

open ansible/ngrok/tasks/main.yml and modify it like below.

---
- name: Unarchive ngrok
  become: true
  unarchive:
    src: ngrok.zip
    dest: /vagrant
  tags:
    - ngrok

actually, this role just unarchives the file. let’s download the file needed at here.

or you can download from our repository.

copy it to ansible/files.

modify ansible/playbook.yml like below to use ngrokrole.

---
- hosts: localhost
  connection: local
  roles:
    - init
    - docker
    - laradock
    - php
    - ngrok

Execute Virtual Machine

execute below command to start the virtual machine(Guest System).

vagrant up

if you execute this for the first time, it takes a long time. also, it executes automatically ngrok setting we added above.

if you’ve already executed the virtual machine with our Ansible configuration, you need to do belows.

# vagrant up
vagrant ssh
sudo ansible-playbook /vagrant/ansible/playbook.yml --tags 'ngrok'

Execute ngrok

execute below command to start ngrok.

# vagrant ssh
cd /vagrant/
./ngrok http 80

and then, you can see below screen.

Session Status                online
Session Expires               7 hours, 59 minutes
Version                       2.2.8
Region                        Asia Pacific (ap)
Web Interface                 http://127.0.0.1:4040
Forwarding                    http://cf354047.ap.ngrok.io -> localhost:80
Forwarding                    https://cf354047.ap.ngrok.io -> localhost:80

you can access the virtual machine(Guest System) by Forwarding URL in here. this is only for testing and developing, use it when you develop or test the application.

Completed

to develop api server for App, you can easily use api server on the virtual machine(Guest System) in the local machine(Host System) by ngrok.

you can see our Laravel virtual machine(Guest System) by Ansible, at below link.

Was my blog helpful? Please leave a comment at the bottom. it will be a great help to me!

App promotion

You can use the applications that are created by this blog writer Deku.
Deku created the applications with Flutter.

If you have interested, please try to download them for free.

Posts