Cloudflare Tunnel Setup Guide for Localhost Applications
Prerequisites
Install cloudflare tunnel for your local machine.
Step 1: Create a Cloudflare Tunnel
-
Open a terminal and run:
Replace<tunnel-name>
with a name for your tunnel. -
Note the Tunnel ID from the output. You'll need this later.
Step 2: Create the Configuration File
-
Create a new YAML file:
Replace<app-name>
with your application name (e.g., plex, nextcloud). -
Add the following content to the file:
Replace the placeholders: <tunnel-id>
: The Tunnel ID from step 1<your-username>
: Your system username<app-subdomain>
: The subdomain for your app (e.g., plex, nextcloud)<your-domain>
: Your actual domain name-
<port>
: The local port your application uses (e.g., 32400 for Plex) -
Save and exit the editor (Ctrl+X, then Y, then Enter in nano).
Step 3: Configure DNS
- Log in to your Cloudflare dashboard.
- Go to the DNS settings for your domain.
- Add a CNAME record:
- Type: CNAME
- Name:
<app-subdomain>
(e.g., plex, nextcloud) - Target:
<tunnel-id>.cfargotunnel.com
- Proxy status: Proxied (orange cloud icon)
Step 4: Start the Tunnel
- Run the tunnel:
Step 5: Configure Your Application (if necessary)
For some applications, you may need to update their settings:
- Open your application's settings.
- Look for options like "Custom URLs", "Remote Access", or "Trusted Proxies".
- Add your Cloudflare Tunnel URL:
https://<app-subdomain>.<your-domain>.com
Step 6: Access Your Application
- Open a web browser.
- Go to
https://<app-subdomain>.<your-domain>.com
Troubleshooting
If you encounter issues:
1. Ensure your application is running and accessible at http://localhost:<port>
2. Check the cloudflared logs for any error messages
3. Verify your Cloudflare DNS settings
4. Check your application's logs for any connection or proxy-related issues
Remember to replace all placeholders with your actual values when following these steps.