Accessing an IP camera through caddy

1. Output of caddy version:

v2.6.2

2. How I run Caddy:

cam.site.me {
reverse_proxy rtmp://192.168.4.202/bcs/channel0_main.bcs?channel=0&stream=0
}

a. System environment:

Ubuntu server 22.04, systemd

b. Command:

sudo systemctl reload caddy

c. Service/unit/compose file:

cam.site.me {
        reverse_proxy rtmp://192.168.4.202/bcs/channel0_main.bcs?channel=0&stream=0
}

d. My complete Caddy config:

cam.site.me {
        reverse_proxy rtmp://192.168.4.202/bcs/channel0_main.bcs?channel=0&stream=0
}

3. The problem I’m having:

I am trying to access a rtmp stream of an internal IP camera, from the internet using a web browser. The config above is what I have tried, but no luck so far.

4. Error messages and/or full log output:

?

5. What I already tried:

I have tried the above config using HTTP, RTSP and RTMP streams

6. Links to relevant resources:

Caddy’s standard distribution is an HTTP server and proxy. It can’t proxy RTMP because that’s not HTTP.

You could use GitHub - mholt/caddy-l4: Layer 4 (TCP/UDP) app for Caddy plugin which would let you proxy raw TCP (including RTMP).

1 Like

my camera can also output the stream over HTTP in this format:

http://192.168.0.2/flv?port=1935&app=bcs&stream=channel0_main.bcs&user=admin&password=123456

anything I can do with this?

You could possibly try this:

cam.site.me {
	rewrite * /flv?port=1935&app=bcs&stream=channel0_main.bcs&user=admin&password=123456
	reverse_proxy 192.168.0.2
}

I tried it. Caddy reloads with no errors, but page does not load.

:man_shrugging:

Not much I can do with that information (or lack thereof).

Ye, please provide more information.

Have a look at your web browsers’ network tab in the dev tools.
You could also compare the network tab when you open http://192.168.0.2/flv?port=1935&app=bcs&stream=channel0_main.bcs&user=admin&password=123456 vs cam.site.me.

And enable http access logs in Caddy, like so:

cam.site.me {
	rewrite * /flv?port=1935&app=bcs&stream=channel0_main.bcs&user=admin&password=123456
	reverse_proxy 192.168.0.2
	log
}

To read those just enabled logs, use journalctl -u caddy --no-pager | less +G, as mentioned in Keep Caddy Running — Caddy Documentation :innocent:

1 Like

:slight_smile:
Yes, I understand. But being a newbie I could only help you with further info if you tell me where and how to look.

The http://192… works well in the web browser. Only through cam.site.me does not work.
PS cam.site.me is not the real domain I use, but it should not have an effect on my issue. I use other links in my caddyfile (eg cloud.site.me), and they all work ok.

I am not sure where to paste the log (output of journalctl -u caddy --no-pager | less +G) because it’s huge, but the part since the last caddy reload can be seen here.

I figured something out…
@IndeedNotJames 's reply was of great help.

When I access the internal IP stream address through a browser (eg. “http://192.168.0.2…”), the stream worked fine.
When I tried to access the stream through the domain name (eg. “cam.site.me…”) the page was not loadig, BUT ONLY FROM MY INTERNAL NETWORK. If I use a VPN or access this domain from anywhere outside of my network, everything worked as expected.

Anyways, thank you @francislavoie and @IndeedNotJames for putting up with someone with my embarrassing level of IT skills.

Ah that makes sense. That’s typically because your router doesn’t support NAT hairpinning, i.e. it doesn’t know how to route connections to your WAN IP back into your local network. See Network address translation - Wikipedia

One way to solve that is to use a DNS server in your local network to make that domain resolve to your LAN IP instead for devices inside your network. Or use a different domain which you make resolve to your LAN IP, if you don’t absolutely need it to be the same domain (for cookies to be remembered by the browser, or whatever).

2 Likes

This topic was automatically closed after 30 days. New replies are no longer allowed.