Setting up a home server means exposing your private services to the internet. In the past, the most popular way by port-forwarding through the router, which is quite risky. Nowadays, most ISPs block access to router settings and don't allow port-forwarding.
An alternative is to tunnel your local port through service providers that expose your service to the internet. These tunnel providers add the necessary security, making it safer than port-forwarding. However, while slightly more secure, this is not a very secure option overall. If security is important to you, consider using a VPN instead.
Cloudflare Tunnels
To use Cloudflare Tunnels, there are some prerequisites:
Cloudflare account
A domain
You have to add your domain to the Cloudflare account first. Follow these steps to add the tunnel:
Go to Zero Trust in the sidebar - You will be navigated to one.dash.cloudflare
Go to Networks
Go to Tunnel
Add Tunnel
Now run the below command in your terminal. Disclaimer: Doing this will spawn a daemon with root permission, which can stay as a middleman between you and the internet. So do this if you trust Cloudflare. Again, I advertise using private VPN over this method.
After the command runs successfully, basic setup for the tunnel is completed. Now we define which port to tunnel and to what domain.
After saving the settings. We will be able to access the port 80 of our local machine via testy.buddhag.com.np
. This is the entry point to HTTP request in my machine, which is running nginx in that port.
Congratulations, you have successfully tunneled your local port to the internet.