okay really final commit did the cloudflare setup properly
This commit is contained in:
parent
b5c2ac1013
commit
dcd289e7db
@ -1,10 +1,14 @@
|
|||||||
# Setting Up Cloudflare Tunnel for ABforAbortion Website
|
# Setting Up Cloudflare Tunnel for Your Website: A Beginner's Guide
|
||||||
|
|
||||||
This guide will walk you through the process of setting up a Cloudflare Tunnel to securely expose your ABforAbortion website to the internet without opening ports on your firewall.
|
This guide will walk you through the process of setting up a Cloudflare Tunnel to securely expose your website to the internet without opening ports on your firewall. This is perfect for beginners who want to host a website securely.
|
||||||
|
|
||||||
|
## What is Cloudflare Tunnel?
|
||||||
|
|
||||||
|
Cloudflare Tunnel creates a secure connection between your local web server and Cloudflare's network, allowing visitors to access your site through Cloudflare without exposing your server's IP address.
|
||||||
|
|
||||||
## Prerequisites
|
## Prerequisites
|
||||||
|
|
||||||
1. A Cloudflare account
|
1. A Cloudflare account (free tier works fine)
|
||||||
2. A domain registered and using Cloudflare DNS
|
2. A domain registered and using Cloudflare DNS
|
||||||
3. Docker and Docker Compose installed on your server
|
3. Docker and Docker Compose installed on your server
|
||||||
|
|
||||||
@ -24,15 +28,15 @@ sudo dpkg -i cloudflared.deb
|
|||||||
cloudflared login
|
cloudflared login
|
||||||
```
|
```
|
||||||
|
|
||||||
This command will open a browser window. Log in to your Cloudflare account and authorize the cloudflared application to access your account.
|
This command will open a browser window. Log in to your Cloudflare account and authorize the cloudflared application to access your account. This allows the tunnel to connect to your Cloudflare account.
|
||||||
|
|
||||||
## Step 3: Create a Tunnel
|
## Step 3: Create a Tunnel
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cloudflared tunnel create abforabortion-tunnel
|
cloudflared tunnel create my-website-tunnel
|
||||||
```
|
```
|
||||||
|
|
||||||
This will create a new tunnel and store the credentials in `~/.cloudflared/[TUNNEL-ID].json`.
|
This will create a new tunnel and store the credentials in `~/.cloudflared/[TUNNEL-ID].json`. The tunnel ID is a unique identifier for your tunnel.
|
||||||
|
|
||||||
## Step 4: Get Your Tunnel ID
|
## Step 4: Get Your Tunnel ID
|
||||||
|
|
||||||
@ -40,49 +44,77 @@ This will create a new tunnel and store the credentials in `~/.cloudflared/[TUNN
|
|||||||
cloudflared tunnel list
|
cloudflared tunnel list
|
||||||
```
|
```
|
||||||
|
|
||||||
Note the tunnel ID - you'll need to update it in the `cloudflared-config.yml` file.
|
Note the tunnel ID - you'll need this for the next steps. It should look something like a UUID (e.g., "6ff42ae2-765d-4adf-8112-31c55c1551ef").
|
||||||
|
|
||||||
## Step 5: Set Up DNS Records
|
## Step 5: Set Up DNS Records
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Replace with your actual domain and tunnel ID
|
# Replace with your actual domain and tunnel ID
|
||||||
cloudflared tunnel route dns your-tunnel-id abforabortion.com
|
cloudflared tunnel route dns your-tunnel-id yourdomain.com
|
||||||
cloudflared tunnel route dns your-tunnel-id www.abforabortion.com
|
cloudflared tunnel route dns your-tunnel-id www.yourdomain.com
|
||||||
```
|
```
|
||||||
|
|
||||||
## Step 6: Update the Configuration File
|
This links your domain name to the tunnel, allowing traffic to flow to your local server.
|
||||||
|
|
||||||
Edit the `cloudflared-config.yml` file:
|
## Step 6: Configure Your Tunnel
|
||||||
|
|
||||||
1. Replace `your-tunnel-id` with your actual tunnel ID
|
Use the provided `cloudflared-config.yml` file and update the following:
|
||||||
2. Update the hostnames to match your domain
|
|
||||||
|
|
||||||
## Step 7: Start the Docker Containers
|
```yaml
|
||||||
|
tunnel: your-tunnel-id # Replace with your actual tunnel ID
|
||||||
|
credentials-file: /root/.cloudflared/your-tunnel-id.json # Update with your tunnel ID
|
||||||
|
```
|
||||||
|
|
||||||
|
Also update the hostname in the ingress section to match your domain:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
ingress:
|
||||||
|
- hostname: yourdomain.com # Replace with your actual domain
|
||||||
|
service: http://localhost:80
|
||||||
|
```
|
||||||
|
|
||||||
|
## Step 7: Start the Tunnel Using Docker Compose
|
||||||
|
|
||||||
|
We've provided a Docker Compose file that sets up both your web server and the Cloudflare tunnel:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
# Start the services
|
||||||
docker-compose -f docker-compose-with-cloudflare.yml up -d
|
docker-compose -f docker-compose-with-cloudflare.yml up -d
|
||||||
|
|
||||||
|
# Check the status
|
||||||
|
docker-compose -f docker-compose-with-cloudflare.yml ps
|
||||||
```
|
```
|
||||||
|
|
||||||
|
This will start both your web server and the Cloudflare tunnel service connecting it to the internet.
|
||||||
|
|
||||||
## Step 8: Monitor the Tunnel
|
## Step 8: Monitor the Tunnel
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Check logs
|
# Check logs from your Docker setup
|
||||||
docker-compose -f docker-compose-with-cloudflare.yml logs -f cloudflared
|
docker-compose -f docker-compose-with-cloudflare.yml logs -f cloudflared
|
||||||
|
|
||||||
# Check status
|
# Check tunnel status using the CLI
|
||||||
cloudflared tunnel info your-tunnel-id
|
cloudflared tunnel info your-tunnel-id
|
||||||
```
|
```
|
||||||
|
|
||||||
## Troubleshooting
|
## Troubleshooting
|
||||||
|
|
||||||
- **Connection issues**: Check if the cloudflared container can access the web container
|
- **Connection issues**: Check if your web server is running and accessible locally
|
||||||
- **DNS issues**: Verify DNS records in your Cloudflare dashboard
|
- **DNS issues**: Verify DNS records in your Cloudflare dashboard (orange cloud should be enabled)
|
||||||
- **Authentication issues**: Ensure credentials file exists and is mounted correctly
|
- **Authentication issues**: Ensure credentials file exists and contains valid information
|
||||||
|
- **"No such tunnel" error**: Double-check your tunnel ID in all configurations
|
||||||
|
|
||||||
## Security Considerations
|
## Security Benefits
|
||||||
|
|
||||||
- The Cloudflare Tunnel provides secure access without exposing your server's IP address
|
- Your server's IP address remains hidden from the public
|
||||||
- All traffic is encrypted between visitors and your origin server
|
- All traffic is encrypted between visitors and your server
|
||||||
- Authentication happens via Cloudflare's authentication system
|
- Protection from DDoS attacks via Cloudflare's network
|
||||||
|
- No need to open ports in your firewall
|
||||||
|
|
||||||
|
## Next Steps
|
||||||
|
|
||||||
|
- Set up Cloudflare Access for additional authentication
|
||||||
|
- Configure Cloudflare Workers for edge computing capabilities
|
||||||
|
- Explore Cloudflare Pages for static site hosting
|
||||||
|
|
||||||
For more information, visit the [Cloudflare Tunnel documentation](https://developers.cloudflare.com/cloudflare-one/connections/connect-apps/).
|
For more information, visit the [Cloudflare Tunnel documentation](https://developers.cloudflare.com/cloudflare-one/connections/connect-apps/).
|
||||||
|
@ -1,28 +1,24 @@
|
|||||||
## Cloudflare Tunnel configuration file
|
## Cloudflare Tunnel configuration file
|
||||||
## This config connects your local website to the internet securely using Cloudflare Tunnels
|
## This connects your local website to the internet securely without exposing your IP address
|
||||||
|
|
||||||
# Tunnel configuration
|
# Tunnel configuration - UPDATE THESE VALUES
|
||||||
tunnel: your-tunnel-id # Replace with your actual tunnel ID from Cloudflare
|
tunnel: your-tunnel-id # Replace with your actual tunnel ID from Step 4
|
||||||
credentials-file: /root/.cloudflared/your-tunnel-id.json # Path to your tunnel credentials file
|
credentials-file: /root/.cloudflared/your-tunnel-id.json # Use your tunnel ID here too
|
||||||
|
|
||||||
# Ingress rules define how traffic is routed
|
# Ingress rules define how traffic is routed to your services
|
||||||
ingress:
|
ingress:
|
||||||
# First rule: route all traffic to your local website
|
# Route traffic from your domain to your local web server
|
||||||
- hostname: abforabortion.com # Replace with your domain
|
- hostname: yourdomain.com # Replace with your actual domain
|
||||||
service: http://localhost:80
|
service: http://web:80 # This targets the web service in docker-compose
|
||||||
|
|
||||||
# Second rule: you can add additional hostnames/subdomains
|
# Catch-all rule (required) - returns 404 for any other requests
|
||||||
- hostname: www.abforabortion.com # Replace with your subdomain
|
|
||||||
service: http://localhost:80
|
|
||||||
|
|
||||||
# Default catch-all rule (required)
|
|
||||||
- service: http_status:404
|
- service: http_status:404
|
||||||
|
|
||||||
# Log level options: debug, info, warn, error, fatal
|
# Log settings
|
||||||
logfile: /var/log/cloudflared.log
|
logfile: /var/log/cloudflared.log
|
||||||
loglevel: info
|
loglevel: info # Options: debug, info, warn, error, fatal
|
||||||
|
|
||||||
# Optional: Set to true in production
|
# Connection settings
|
||||||
originRequest:
|
originRequest:
|
||||||
connectTimeout: 30s
|
connectTimeout: 30s
|
||||||
noTLSVerify: false
|
noTLSVerify: false # Keep this false for security
|
||||||
|
@ -1,31 +1,32 @@
|
|||||||
version: '3'
|
version: '3'
|
||||||
|
|
||||||
services:
|
services:
|
||||||
# Your existing web server
|
# Web server - serves your website content
|
||||||
web:
|
web:
|
||||||
image: nginx:alpine
|
image: nginx:alpine
|
||||||
ports:
|
ports:
|
||||||
- "80:80"
|
- "80:80" # Only exposed locally, not to the internet
|
||||||
volumes:
|
volumes:
|
||||||
- ./website:/usr/share/nginx/html
|
- ./website:/usr/share/nginx/html # Your website files go in the "website" folder
|
||||||
- ./nginx.conf:/etc/nginx/conf.d/default.conf
|
- ./nginx.conf:/etc/nginx/conf.d/default.conf # Nginx configuration
|
||||||
restart: always
|
restart: always
|
||||||
networks:
|
networks:
|
||||||
- web_network
|
- web_network
|
||||||
|
|
||||||
# Cloudflare tunnel service
|
# Cloudflare tunnel service - connects your website to the internet securely
|
||||||
cloudflared:
|
cloudflared:
|
||||||
image: cloudflare/cloudflared:latest
|
image: cloudflare/cloudflared:latest
|
||||||
command: tunnel --config /etc/cloudflared/config.yml run
|
command: tunnel --config /etc/cloudflared/config.yml run
|
||||||
volumes:
|
volumes:
|
||||||
- ./cloudflared-config.yml:/etc/cloudflared/config.yml:ro
|
- ./cloudflared-config.yml:/etc/cloudflared/config.yml:ro # Your tunnel configuration
|
||||||
- ~/.cloudflared:/root/.cloudflared:ro # Mount credentials from host
|
- ~/.cloudflared:/root/.cloudflared:ro # Your tunnel credentials
|
||||||
restart: always
|
restart: always
|
||||||
depends_on:
|
depends_on:
|
||||||
- web
|
- web # Ensures web service starts first
|
||||||
networks:
|
networks:
|
||||||
- web_network
|
- web_network
|
||||||
|
|
||||||
|
# Network used by both services to communicate
|
||||||
networks:
|
networks:
|
||||||
web_network:
|
web_network:
|
||||||
driver: bridge
|
driver: bridge
|
||||||
|
Loading…
x
Reference in New Issue
Block a user