TunnelForge is a lightweight, open-source, self-hosted alternative to ngrok that provides tunneling services for exposing local applications to the internet. It supports HTTP, WebSocket, and any other TCP-based protocols, allowing seamless integration with modern applications.
Click the image above to watch the TunnelForge demo and learn how it works in action!
- Expose local services to the internet with unique subdomains.
- Support for HTTP, WebSocket, and other TCP-based protocols.
- Easy setup for local and public servers.
- Support for environment-based configurations.
- Daemonized server processes with PM2.
- DNS configuration support via Cloudflare.
- Future Docker support for containerized deployments.
- Clone the repository:
git clone https://github.com/elshadaghazade/tunnelforge.git cd tunnelforge
- Install dependencies:
npm install
- Build the project:
npm run build
- Start the server:
The server will generate a static subdomain (sub1).
npm run server:dev
- Add an entry to your local
/etc/hosts
file:127.0.0.1 sub1.myproxy.com
- Start the client:
npm run client:dev -- -h myproxy.com -p [SERVER_PORT_FROM_ENV] -q [LOCAL_APP_PORT] -r [LOCAL_APP_HOST]
- Access your application using:
http://sub1.myproxy.com:[INCOMING_PORT_FROM_ENV]
- On the server:
- Open ports for
CLIENT_SERVER_PORT
andINCOMING_SERVER_PORT
in your cloud environment (e.g., AWS EC2). - Configure DNS in Cloudflare:
- Create an
A
record for*.yourdomain.com
pointing to your server's IP.
- Create an
- Run the server:
npm run server:prod
- PM2 users can daemonize the process:
pm2 start ecosystem.config.js
- Open ports for
- On the client:
- Build the client:
npm run build
- Run the client:
npm run client:prod -- -h yourdomain.com -p [SERVER_PORT_FROM_ENV] -q [LOCAL_APP_PORT] -r [LOCAL_APP_HOST]
- After connecting, the client logs the public address:
Your public address is http://[UNIQUE_SUBDOMAIN].yourdomain.com:[INCOMING_PORT_FROM_ENV]
- Access your public application using the generated public address.
- Build the client:
Set these variables in your .env.development
or .env.production
file:
NODE_ENV=production
CLIENT_SERVER_PORT=4000
INCOMING_SERVER_PORT=4001
SERVER_CLIENT_HOST=0.0.0.0
SERVER_INCOMING_HOST=0.0.0.0
RECONNECT_INTERVAL=1000
PROXY_SERVER_MAIN_HOST=globalmedbooking.com
CLIENT_PARAM_SERVER_HOST=127.0.0.1
CLIENT_PARAM_SERVER_PORT=4000
CLIENT_PARAM_LOCAL_APP_HOST=127.0.0.1
CLIENT_PARAM_LOCAL_APP_PORT=3010
You can easily run both the TunnelForge server and client using Docker. This approach simplifies deployment, ensuring a consistent environment for running the application
-
Prepare the
.env
FileCreate an .env file in the root directory with the following contents, adjusting the values to match your desired configuration:
NODE_ENV=production CLIENT_SERVER_PORT=4000 INCOMING_SERVER_PORT=4001 SERVER_CLIENT_HOST=0.0.0.0 SERVER_INCOMING_HOST=0.0.0.0 RECONNECT_INTERVAL=1000 PROXY_SERVER_MAIN_HOST=yourcustomdomain.com CLIENT_PARAM_SERVER_HOST=127.0.0.1 CLIENT_PARAM_SERVER_PORT=4000 CLIENT_PARAM_LOCAL_APP_HOST=127.0.0.1 CLIENT_PARAM_LOCAL_APP_PORT=3010
- Server Environment Variables:
CLIENT_SERVER_PORT
andINCOMING_SERVER_PORT
: Ports exposed by the TunnelForge server.PROXY_SERVER_MAIN_HOST
: Your main domain to handle subdomains.
- Client Parameters:
CLIENT_PARAM_SERVER_HOST
andCLIENT_PARAM_SERVER_PORT
: Host and port of the TunnelForge server.CLIENT_PARAM_LOCAL_APP_HOST
andCLIENT_PARAM_LOCAL_APP_PORT
: Host and port of the local application to expose.
- Server Environment Variables:
-
Build and Run with Docker Compose
The provided
docker-compose.yml
file is configured to build and run both the server and client. To start everything, simply run:docker compose up -d
-
Server and Client Communication
- The server will listen on the ports specified in
CLIENT_SERVER_PORT
andINCOMING_SERVER_PORT
. - The client will forward requests to your local application and make it publicly accessible via the
PROXY_SERVER_MAIN_HOST
and generated subdomain.
- The server will listen on the ports specified in
-
Accessing Your Public URL
After starting the services, the client will log the public URL for accessing your local application. This will be in the format:
http://[generated-subdomain].yourcustomdomain.com:[INCOMING_SERVER_PORT]
-
Explore the Docker Images
You can find the Docker images for TunnelForge on Docker Hub:
We welcome contributions! See our Contributing Guidelines for details.
TunnelForge is licensed under the MIT License.
Visit the official website of TunnelForge for more details: tunnelforge.org.
The full API and usage documentation is hosted on GitHub Pages.
If you'd like to view it locally or use it in a different hosting platform, the documentation is generated using TypeDoc and is located in the /docs folder.
Happy tunneling with TunnelForge!