Tunnel a Web Application Using Cloudflared

  1. Configure the domain in Cloudflared; set the DNS addresses in the provider (Route53, NameCheap, GoDaddy, etc.) with the values stablished by Cloudflare.

    https://dash.cloudflare.com/

  2. Download and install the client

    https://github.com/cloudflare/cloudflared/releases

    or

    If using Termux (Android), just install the package

    pkg install cloudflared
    
  3. Install the certificate

    cloudflared tunnel login
    

    Copy the path of the generated JSON, it is the credentials-file required in next steps.

    1. Create the tunnel
    cloudflared tunnel create {name}
    
  4. Modify the config.yml file (example)

    tunnel: {uuid}
    credentials-file: /path/to/.cloudflared/{uuid}.json
    ingress:
      - hostname: {domain}
        service: http://localhost:{port}
      - service: http_status:404
    
  5. Route the DNS

    cloudflared tunnel route dns {tunnel} {domain}
    

    The target domain or subdomain should be used. This step creates the entry in the DNS records.

  6. Start the tunnel

    cloudflared tunnel run {tunnel}
    
  7. Install the service (Not available in Termux)

    sudo cloudflared service install
    

Additional Info

It is possible to link other domains to the tunnel, go to the domain configuration and copy the CNAME entry, the one that has {...}.cfargotunnel.com, add the domain to the config.yml file and configure nginx like this:

http {
...
  server {
    listen 80 default_server;
    server_name firstdomain.com;
    ...
  }
  server {
    listen 80;
    server_name seconddomain.com;
    ...
  }
}

Open source alternatives:
https://github.com/anderspitman/awesome-tunneling

linux net

Back