1. The problem I’m having:
Hello, I’m wondering if there’s a way to get the actual IP of the client in my setup. I’m running Caddy and Cloudflare Tunnels (cloudflared) in LXC containers on Proxmox (doing a new install after moving Caddy away from Unraid). Each of the containers has their own IP.
I want to block certain domains to local access only or tailscale only (if possible) while leaving others free to be accessed by any IP range. Currently when accessing sites I get remote_ip and client_ip in logs as my Cloudflared LXC container’s IP.
Cloudflared LXC IP: 192.168.86.13
I’ve searched over the forums and google and tried multiple things but never was able to solve this. Gave up and now I’m here asking for help because it’s bugging me.
2. Error messages and/or full log output:
Just confirms what I’m seeing
2024/11/07 17:21:35.812	e[34mINFOe[0m	http.log.access.log2	handled request	{"request": {"remote_ip": "192.168.86.13", "remote_port": "52486", "client_ip": "192.168.86.13", "proto": "HTTP/1.1", "method": "GET", "host": "test.domain.com", "uri": "/", "headers": {"Connection": ["keep-alive"], "Dnt": ["1"], "Priority": ["u=0, i"], "Upgrade-Insecure-Requests": ["1"], "Accept-Language": ["en-US,en;q=0.9"], "Cf-Ipcountry": ["US"], "Cf-Visitor": ["{\"scheme\":\"https\"}"], "Sec-Fetch-Mode": ["navigate"], "Sec-Fetch-User": ["?1"], "Cache-Control": ["max-age=0"], "Cf-Warp-Tag-Id": ["f984e815-8ffe-4030-b167-bffba16c5ccd"], "Sec-Ch-Ua": ["\"Chromium\";v=\"130\", \"Google Chrome\";v=\"130\", \"Not?A_Brand\";v=\"99\""], "Cf-Ray": ["8def00251ba03b8c-IAD"], "Sec-Ch-Ua-Platform": ["\"macOS\""], "X-Forwarded-Proto": ["https"], "User-Agent": ["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36"], "Accept": ["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8"], "Sec-Ch-Ua-Mobile": ["?0"], "Sec-Fetch-Dest": ["document"], "Sec-Fetch-Site": ["none"], "X-Forwarded-For": ["173.163.124.234"], "Accept-Encoding": ["gzip, br"], "Cdn-Loop": ["cloudflare; loops=1"], "Cf-Connecting-Ip": ["173.163.124.234"]}, "tls": {"resumed": false, "version": 772, "cipher_suite": 4865, "proto": "", "server_name": "test.domain.com"}}, "bytes_read": 0, "user_id": "", "duration": 0.043235828, "size": 5, "status": 200, "resp_headers": {"Content-Type": ["text/plain; charset=utf-8"], "Server": ["Caddy"], "Alt-Svc": ["h3=\":443\"; ma=2592000"], "Referrer-Policy": ["strict-origin"], "Strict-Transport-Security": ["max-age=31536000; includeSubDomains;"], "X-Content-Type-Options": ["nosniff"], "X-Frame-Options": ["SAMEORIGIN"], "X-Robots-Tag": ["noindex, nofollow, nosnippet, noarchive"]}}
3. Caddy version:
Running Caddy v2.8.4
4. How I installed and ran Caddy:
a. System environment:
LXC container running Debian 12.
b. Command:
Ran using this script: ProxmoxVE/install/caddy-install.sh at main · community-scripts/ProxmoxVE · GitHub (the commands of interest are below)
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' >/etc/apt/sources.list.d/caddy-stable.list
apt-get update
apt-get install -y caddy
c. Service/unit/compose file:
Type=notify
User=caddy
Group=caddy
ExecStart=/usr/bin/caddy run --environ --config /etc/caddy/Caddyfile
ExecReload=/usr/bin/caddy reload --config /etc/caddy/Caddyfile --force
TimeoutStopSec=5s
LimitNOFILE=1048576
PrivateTmp=true
ProtectSystem=full
AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
[Install]
WantedBy=multi-user.target
d. My complete Caddy config:
{
	email caddy@domain.com
	servers {
		trusted_proxies cloudflare
		client_ip_headers CF-Connecting-IP
	}
}
(security_headers) {
	header {
		Strict-Transport-Security "max-age=31536000; includeSubDomains;"
		X-Frame-Options "SAMEORIGIN"
		X-Content-Type-Options "nosniff"
		Referrer-Policy "strict-origin"
		X-Robots-Tag "noindex, nofollow, nosnippet, noarchive"
	}
}
(log_settings) {
	log {
		output file /var/log/caddy/caddylog.log {
			roll_size 10MiB
			roll_keep 2
			roll_keep_for 72h
		}
		level DEBUG
		format console
	}
}
(cloudflare) {
	tls {
		dns cloudflare <token>
	}
}
(simple_lb) {
	lb_policy first
	lb_try_duration 5s
	lb_try_interval 250ms
	fail_duration 10s
	max_fails 1
	unhealthy_status 5xx
	unhealthy_latency 5s
	unhealthy_request_count 1
}
:80 {
	import log_settings
	root * /usr/share/caddy
	file_server
}
*.domain.com {
	import cloudflare
	import log_settings
	import security_headers
	@test host test.domain.com
	handle @test {
		respond "Works."
	}
	handle {
		abort
	}
}
5. Links to relevant resources:
Searched all over looking for people with similar-ish problems (including the most recent help topic) but they rarely had the same setup and tried their working solutions but nothing worked for me so far.
 , I had an issue and realized that config only worked with AdGuard Home. I’ve turned that off as it’s causing other issues within my network currently.
, I had an issue and realized that config only worked with AdGuard Home. I’ve turned that off as it’s causing other issues within my network currently.