80 lines
2.5 KiB
Markdown
80 lines
2.5 KiB
Markdown
# Cloudflare Tunnel Setup Guide for Localhost Applications
|
|
|
|
## Prerequisites
|
|
|
|
Install[ cloudflare tunnel ](https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/get-started/)for your local machine.
|
|
## Step 1: Create a Cloudflare Tunnel
|
|
|
|
1. Open a terminal and run:
|
|
```
|
|
cloudflared tunnel create <tunnel-name>
|
|
```
|
|
Replace `<tunnel-name>` with a name for your tunnel.
|
|
|
|
2. Note the Tunnel ID from the output. You'll need this later.
|
|
|
|
## Step 2: Create the Configuration File
|
|
|
|
1. Create a new YAML file:
|
|
```
|
|
nano ~/.cloudflared/config-<app-name>.yml
|
|
```
|
|
Replace `<app-name>` with your application name (e.g., plex, nextcloud).
|
|
|
|
2. Add the following content to the file:
|
|
```yaml
|
|
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)
|
|
|
|
3. Save and exit the editor (Ctrl+X, then Y, then Enter in nano).
|
|
|
|
## Step 3: Configure DNS
|
|
|
|
1. Log in to your Cloudflare dashboard.
|
|
2. Go to the DNS settings for your domain.
|
|
3. 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
|
|
|
|
1. 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:
|
|
|
|
1. Open your application's settings.
|
|
2. Look for options like "Custom URLs", "Remote Access", or "Trusted Proxies".
|
|
3. Add your Cloudflare Tunnel URL: `https://<app-subdomain>.<your-domain>.com`
|
|
|
|
## Step 6: Access Your Application
|
|
|
|
1. Open a web browser.
|
|
2. 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. |