Notebook for Local App Server

There will be a provision very basic self-hosting technic, in order to prevent storage and configuration paramount for your host machine, instead, we will be using an external SSD as a double-virtual-private-server.

Setup Multipass to Work in External Storage

Follow instructions in Notebook of Multipass post to externalize Multipass Environment.

Create Multipass Instance

multipass launch --cpu 2 --mem 2G --disk 24G --name cheeky-peacock jammy

Configure Multipass Instance as VPS

multipass shell cheeky-peacock

Set a FQDN domain-name when you are in SSH session there by sudo hostnamectl set-hostname cheeky.local or any domain name you’d like to give to you VM.

Create and Serve App Container

  1. Install Docker by following instructions in documentation;
  2. Install Portainer Community Edition;
  3. Setup all in Portainer Dashboard as desired, self-signed SSL certificates, user management etc. The default config is quite enough to go.

Setup Reverse Proxy

When you get satisfied of tweaking Portainer control panel switches enough, install Nginx Proxy Manager as a stack through inside Portainer from App Templates, from the loveliest page of the Portainer dashboard.

When NPM is up and running, go to its dashboard via the ip address and 81 port number. You’ll be needed to start an account before continue.

At the dashboard of NPM initialize a Proxy Host.

  1. Give a desired domain name: testing-myapp.cheepee.vm.
  2. Scheme: http (yet we don’t use local SSL)
  3. Forward Hostname / IP: the multipass instance’s IP, 10.10.10.111
  4. Forward Port: 3000, which is the exposed port number from docker container that runs a nodejs app inside with that port number just in our example.
  5. Most crucial part, don’t forget to put that domain name inside your /etc/hosts file: 10.10.10.111 testing-myapp.cheepe.vm

Let’s say we have an expressJS app that runs at 3337 port and it is responses to the requests to a specific URI like /api then it can be added in the same proxy host item via Custom Locations tab as

  • Define Location: /api
  • Scheme: http
  • Forward Hostname / IP: cheepee.vm/api
  • Forward Port: 3337

by that extra configuration only using the domain name as http://testing-myapp.cheepee.vm will response the requests taken like http://10.10.10.111:3337/api.

That is called cheepee reverse proxy from LAN, even from the same machine.

Configure Host Machine

Add app URLs as long as you created new ones in the line of VM machine’s ip address in /etc/hosts file in your host machine.

# /etc/hosts file
127.0.0.1     localhost
10.10.10.111  cheeky.local app1.cheeky.local app2.cheeky.local  

Conclusion

Congratulations! You have just made yourself have a self-testing-and-working-environment as a VPS even inside your own computer with an external SSD that makes you system free of space and spaghetti configuration with multiple node versions, or local docker storage consuming for each app development. You can multiply that process with more instances for hard configuration for various development environment, like Rust which requires a lot of space and Python which is potentially danger to play with in the same environment.

Bonus suggestion!

I use rclone to sync the project folders inside the VM, getting backup of portainer data constantly or snapshots of the VM on to the cloud services at the background while they are off.