installing_and_configuring_cloudflared_on_an_lxc

Installing and Configuring Cloudflared on an LXC

1. Download and Install Cloudflared

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

2. Authenticate Cloudflared with Cloudflare

  • Run the following command to log in and create a tunnel:
cloudflared tunnel login
  • 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

  • Create the tunnel and give it a name:
cloudflared tunnel create my-tunnel
  • 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

  • Create a configuration file:
sudo nano /etc/cloudflared/config.yml
  • Example configuration:
tunnel: 72a29ddd==== TUNNEL ====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

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

6. Configure NGINX on Raspberry Pi

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

7. Set Up Cloudflared as a Systemd Service

  • Create a systemd service file:
sudo nano /etc/systemd/system/cloudflared.service
  • 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
  • Enable and start the service:
sudo systemctl daemon-reload
sudo systemctl enable cloudflared
sudo systemctl start cloudflared
  • Check the status of the service:
sudo systemctl status cloudflared

8. Verify Tunnel Operation

  • 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.txt · Last modified: 2024/10/17 21:42 by 127.0.0.1