DEV Community

Vasilis Aivalis
Vasilis Aivalis

Posted on

Publish a Proxmox LXC App with Cloudflare Tunnel - even Behind CGNAT

Hosting a website at home is straightforward until you need to make it accessible from the internet. Dynamic IP addresses, router configuration, and Carrier-Grade NAT can quickly complicate things.

For this example, I used a Debian LXC container on Proxmox, Nginx, and Cloudflare Tunnel. The container lives on a dedicated VLAN managed by a UniFi gateway, and visitors reach the website through a public hostname.

In this walkthrough, we’ll build that setup from the network configuration through to a working HTTPS website.

We’ll cover:

  • How Cloudflare Tunnel works behind CGNAT.
  • Creating a dedicated VLAN in UniFi.
  • Configuring Proxmox and creating an LXC container.
  • Installing Nginx and publishing website files.
  • Connecting cloudflared to Cloudflare.
  • Mapping a public hostname to an application.
  • Troubleshooting common networking and deployment problems.

1. Understand the architecture

Cloudflare Tunnel connects your server to Cloudflare. cloudflared is the connector application that runs on your server and establishes the outbound connection.

Visitors connect to Cloudflare, which forwards their requests through the tunnel to your application. You do not need a publicly reachable home IP address or inbound port forwarding.

Our Setup

Why this works with CGNAT
With Carrier-Grade NAT, your ISP places another NAT layer between your router and the public internet. Multiple customers may share a public IPv4 address.

A port-forwarding rule on your home router cannot configure that upstream NAT layer. Consequently, forwarding ports 80 and 443 on your router may still leave your website unreachable.

Cloudflared initiates an outbound connection. Requests return through that established connection, so unsolicited inbound connectivity is unnecessary.

This still requires working outbound internet access: CGNAT does not prevent the approach, but an upstream firewall can block the tunnel’s required traffic.

VLAN, NAT, and “DMZ”
These terms describe different things:

  • VLAN: separates the application’s network from your other networks.
  • NAT: translates addresses as traffic passes through your router.
  • DMZ network: a dedicated network whose access is restricted by firewall policies. In this article, “DMZ” means a separate VLAN. It does not mean enabling a consumer router’s “DMZ host” feature, which forwards unsolicited inbound traffic to a device.

Keep ordinary outbound NAT enabled. No special inbound NAT or port-forwarding rule is needed.

2. Gather the prerequisites

You’ll need:

  • A working Proxmox VE server with a wired network connection.
  • A UniFi gateway and a network path that supports VLANs.
  • A domain using Cloudflare DNS.
  • Access to the Cloudflare dashboard.
  • A Debian LXC template available in Proxmox.
  • A website or application to publish.

An LXC container suits this lightweight Linux workload. Containers share the Proxmox host’s kernel; a VM is an alternative when you want a separate guest kernel. We’ll use an unprivileged container and install the software directly, without Docker or nesting.

3. Create the DMZ network in UniFi

Navigate to UniFi Network → Settings → Networks and create a virtual network with the following settings:

  • Name: DMZ
  • Router: Your UniFi gateway
  • VLAN ID: 30
  • Gateway/Subnet: 192.168.30.1/24
  • DHCP: Enabled (192.168.30.100–192.168.30.200)

Ensure the subnet does not overlap with another network or VPN.

If the gateway provides DNS forwarding for this network, advertise 192.168.30.1 as the DNS server. Otherwise, specify a reachable DNS resolver.

4. Enable VLAN awareness in Proxmox

Navigate to Proxmox → Host → System → Network → vmbr0 → Edit.

  • Enable VLAN aware.
  • Ensure VLAN 30 is within the permitted VLAN range.
  • Preserve the existing management IP, gateway and physical bridge port.
  • Apply the configuration.

Warning: Bridge changes may interrupt management connectivity. Ensure local console access before applying.

The VLAN-aware bridge allows individual guest interfaces to use specific VLAN tags.

5. Create the Debian LXC container

If needed, select template storage in Proxmox, open CT Templates → Templates, and download a supported Debian template. Create CT and make sure that you will include this setttings : Bridge vmbr0 and VLAN tag 30 . For this example we will use CT ID 103.

DNS and startup

  • DNS: 192.168.30.1 (if the gateway provides DNS).
  • Start the container and enable Start at boot under its options.

Verify network connectivity

Run on the Proxmox host:

pct exec 103 -- ip -br addr
pct exec 103 -- ip route
pct exec 103 -- cat /etc/resolv.conf
Enter fullscreen mode Exit fullscreen mode

Expected output:

eth0    UP    192.168.30.187/24
default via 192.168.30.1 dev eth0
Enter fullscreen mode Exit fullscreen mode

Enter the container:

pct enter 103
Enter fullscreen mode Exit fullscreen mode

Run the remaining commands inside the container as root:

ping -c 3 192.168.30.1
getent hosts pkg.cloudflare.com
apt update
Enter fullscreen mode Exit fullscreen mode

A failed ping may indicate blocked ICMP. However, Network is unreachable combined with a missing default route indicates a local networking issue.

Once DHCP works, reserve the container's IP address in UniFi.

6. Install Nginx and create a test website

Install and start Nginx:

apt update
apt install -y nginx curl ca-certificates
systemctl enable --now nginx
Enter fullscreen mode Exit fullscreen mode

Create the website directory:

install -d -m 0755 /var/www/myapp
Enter fullscreen mode Exit fullscreen mode

Create a simple test page:

cat > /var/www/myapp/index.html <<'EOF'
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>My Proxmox Website</title>
</head>
<body>
  <h1>Hello from Proxmox!</h1>
  <p>This website is served by Nginx inside an LXC container.</p>
</body>
</html>
EOF
Enter fullscreen mode Exit fullscreen mode

Configure the Nginx site

Since cloudflared runs inside the same container, configure Nginx to listen exclusively on loopback:

cat > /etc/nginx/sites-available/myapp <<'EOF'
server {
    listen 127.0.0.1:80 default_server;
    server_name myapp.example.com;

    root /var/www/myapp;
    index index.html;

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ /\. {
        deny all;
    }
}
EOF
Enter fullscreen mode Exit fullscreen mode

Disable the default site, enable the new configuration and reload Nginx:

unlink /etc/nginx/sites-enabled/default
ln -s /etc/nginx/sites-available/myapp /etc/nginx/sites-enabled/myapp
nginx -t && systemctl reload nginx
Enter fullscreen mode Exit fullscreen mode

Verify the website:

curl -I http://127.0.0.1
curl http://127.0.0.1
Enter fullscreen mode Exit fullscreen mode

Expected response: HTTP/1.1 200 OK and the test page HTML.

Note: Loopback binding intentionally prevents direct access through the container's LAN IP. Cloudflared accesses Nginx locally.

For direct LAN access, use listen 80 default_server; and enforce access restrictions through the firewall.

Deploy your actual website

Replace the test page with your website files. For example, if your static website is located at /opt/myapp:

install -m 0644 /opt/myapp/index.html /var/www/myapp/index.html
install -m 0644 /opt/myapp/styles.css /var/www/myapp/styles.css
Enter fullscreen mode Exit fullscreen mode

Copy any additional assets, preserving their directory structure.

Deployment considerations:

  • Include images, fonts, PDFs, JavaScript, robots.txt and sitemap files.
  • Keep .git, credentials and environment files outside the web root.
  • For projects requiring a build step, deploy the generated output rather than the source repository.
  • Updating static files does not require an Nginx restart.

7. Create the Cloudflare Tunnel

Ensure your domain is active in Cloudflare. If migrating DNS, preserve existing records, including email records.

Navigate to Cloudflare Dashboard → Networking → Tunnels → Create Tunnel.

  • Name: home-myapp
  • Environment: Linux
  • Architecture: Match your LXC container's architecture.

Keep the connector installation instructions available for the next step.

Depending on the dashboard version, tunnels may be located under Cloudflare One → Networks → Connectors.

Cloudflare Tunnel Setup Documentation

8. Install cloudflared inside the LXC

Add Cloudflare's official package repository:

mkdir -p --mode=0755 /usr/share/keyrings

curl -fsSL https://pkg.cloudflare.com/cloudflare-main.gpg \
  | tee /usr/share/keyrings/cloudflare-main.gpg >/dev/null

echo 'deb [signed-by=/usr/share/keyrings/cloudflare-main.gpg] https://pkg.cloudflare.com/cloudflared any main' \
  > /etc/apt/sources.list.d/cloudflared.list
Enter fullscreen mode Exit fullscreen mode

Install and verify cloudflared:

apt update
apt install -y cloudflared
cloudflared --version
Enter fullscreen mode Exit fullscreen mode

Official cloudflared Package Instructions

Install the tunnel service

Copy the tunnel token from your Cloudflare dashboard:

cloudflared service install YOUR_TUNNEL_TOKEN
Enter fullscreen mode Exit fullscreen mode

Alternatively, avoid exposing the token in Bash history:

read -rsp "Paste tunnel token: " CF_TUNNEL_TOKEN
printf '\n'
cloudflared service install "$CF_TUNNEL_TOKEN"
unset CF_TUNNEL_TOKEN
Enter fullscreen mode Exit fullscreen mode

Security: Treat the tunnel token as a credential. Never expose it in screenshots, repositories or articles. The service still retains its credential locally.

Enable and verify the service:

systemctl enable --now cloudflared
systemctl is-active cloudflared
journalctl -u cloudflared -n 50 --no-pager
Enter fullscreen mode Exit fullscreen mode

The Cloudflare dashboard should now display a Healthy connector.

A healthy tunnel confirms connectivity to Cloudflare, but does not yet expose your website.

9. Link the public hostname to Nginx

Open the home-myapp tunnel and add a Published application route:

  • Subdomain: myapp
  • Domain: example.com
  • Path: Leave blank.
  • Service type: HTTP
  • Service address: 127.0.0.1:80

If the interface uses a single Service URL field, enter:

http://127.0.0.1:80
Enter fullscreen mode Exit fullscreen mode

Save the route to map myapp.example.com to the local Nginx instance.

Cloudflare Application Routing Documentation

Verify the DNS record

Cloudflare should automatically create a proxied DNS record:

Type:    CNAME
Name:    myapp
Target:  <TUNNEL-UUID>.cfargotunnel.com
Proxy:   Enabled
Enter fullscreen mode Exit fullscreen mode

Resolve any conflicting DNS records for myapp. Do not point the hostname to your home WAN IP address.

Test the public website

Open https://myapp.example.com in your browser or run:

curl -I https://myapp.example.com
Enter fullscreen mode Exit fullscreen mode

Also test from an external network, such as a mobile phone with Wi-Fi disabled.

The resulting traffic flow is:

Traffic Flow

Your website is now publicly accessible over HTTPS without exposing Nginx directly or requiring inbound port forwarding on your home router.

Top comments (4)

Collapse
 
dosaygo profile image
DOSAYGO •

When you publish an internal Proxmox web app through Cloudflare Tunnel for outside users, how do you restrict downloads, clipboard copy, or direct DOM access when visitors open it from unmanaged devices?

Collapse
 
aivalisv profile image
Vasilis Aivalis •

Cloudflare Tunnel alone does not restrict downloads or DOM inspection . I have seen that Cloudflare does provide a way of isolating access ( developers.cloudflare.com/learning... ) , but i have never experiment with it .

Collapse
 
dosaygo profile image
DOSAYGO •

Thanks for the detail on Cloudflare Tunnel not restricting downloads or DOM inspection on its own and pointing to clientless browser isolation, I'm building BrowserBox (self-hosted remote browser on Linux) so you can run the browser inside your Proxmox DMZ VLAN and stream the web app to outside visitors while keeping the DOM, downloads, and clipboard off their unmanaged devices: browserbox.io/go/forum-20261126-de...

Thread Thread
 
aivalisv profile image
Vasilis Aivalis •

interesting !! i will definitely try it out !