User Tools

Site Tools


installing_and_configuring_cloudflared_on_an_lxc

This is an old revision of the document!


Installing and Configuring Cloudflared on an LXC

1. Download and Install Cloudflared

  1. Download the `.deb` package:
wget https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb
  1. Install the package using `dpkg`:
sudo dpkg -i cloudflared-linux-amd64.deb
  1. Verify the installation:
cloudflared --version

2. Authenticate Cloudflared with Cloudflare

  1. Run the following command to log in and create a tunnel:
cloudflared tunnel login
  1. The authentication process will prompt you to open a URL in your browser to log in with your Cloudflare account.

3. Create a New Tunnel

  1. Create the tunnel and give it a name:
cloudflared tunnel create my-tunnel
  1. Note the tunnel ID and the location of the `cert.pem` file, which will be used for routing traffic.

4. Configure the Tunnel to Route Traffic

  1. Create a configuration file:
sudo nano /etc/cloudflared/config.yml
  1. Example configuration:
tunnel: 72a29ddd-7ef4-46e3-97ef-cc4d8e3fc2ba
credentials-file: /home/facundo/.cloudflared/72a29ddd-7ef4-46e3-97ef-cc4d8e3fc2ba.json

ingress:
    - hostname: *.facundoitest.space
      service: http://192.168.88.250:443
    - service: http_status:404

5. Run the Tunnel

  1. Start the tunnel:
sudo cloudflared tunnel run my-tunnel
  1. Ensure the tunnel is active and routing traffic correctly.

6. Configure NGINX on Raspberry Pi

  1. Update the NGINX configuration on your Raspberry Pi to handle requests coming from the tunnel.

7. Set Up Cloudflared as a Systemd Service

  1. Create a systemd service file:
sudo nano /etc/systemd/system/cloudflared.service
  1. Add the following configuration:
[Unit]
Description=Cloudflare Tunnel
After=network.target

[Service]
Type=simple
User=facundo
ExecStart=/usr/local/bin/cloudflared tunnel run my-tunnel
Restart=on-failure
RestartSec=5s

[Install]
WantedBy=multi-user.target
  1. Enable and start the service:
sudo systemctl daemon-reload
sudo systemctl enable cloudflared
sudo systemctl start cloudflared
  1. Check the status of the service:
sudo systemctl status cloudflared

8. Verify Tunnel Operation

  1. Ensure that the tunnel is running and NGINX is properly handling requests by checking the logs and testing the subdomains.

Conclusion

Following these steps will ensure that your `cloudflared` tunnel is correctly set up on your LXC and that it integrates smoothly with your existing reverse proxy setup on your Raspberry Pi.

installing_and_configuring_cloudflared_on_an_lxc.1724674839.txt.gz · Last modified: 2024/10/17 21:42 (external edit)