2.5 KiB
2.5 KiB
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:
cloudflared tunnel create <tunnel-name>
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:
nano ~/.cloudflared/config-<app-name>.yml
Replace
<app-name>
with your application name (e.g., plex, nextcloud). -
Add the following content to the file:
tunnel: <tunnel-id> credentials-file: /home/<your-username>/.cloudflared/<tunnel-id>.json ingress: - hostname: <app-subdomain>.<your-domain>.com service: http://localhost:<port> - service: http_status:404
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:
cloudflared tunnel --config ~/.cloudflared/config-<app-name>.yml run
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:
- Ensure your application is running and accessible at
http://localhost:<port>
- Check the cloudflared logs for any error messages
- Verify your Cloudflare DNS settings
- 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.