Redir - One subdomain:port to new subdomain

1. Output of caddy version:

Caddy 2.6.2

2. How I run Caddy:

a. System environment:

Raspberry PI4 with Raspian

b. Command:

caddy start --config /etc/caddy/Caddyfile

c. Service/unit/compose file:

none

d. My complete Caddy config:

{
	log {
		output file /home/admin/Caddy2-logs/caddy2.log
	}
	email admin@example.com
}

openwebif.example.com {
	log {
		output file /home/admin/Caddy2-logs/openwebif.log
	}
	encode gzip
	header Strict-Transport-Security max-age1536000;
	reverse_proxy http://192.168.1.10:80
}

streaming.example.com {
	log {
		output file /home/admin/Caddy2-logs/streaming.log
	}
	encode gzip
	header Strict-Transport-Security max-age1536000;
	reverse_proxy http://192.168.1.10:8001
}

3. The problem I’m having:

I can access both subdomains, but the issue is that openwebif creates an m3u8 file is in the following format:

#EXTM3U
#EXTVLCOPT–http-reconnect=true
#EXTINF:-1,CNN HD
#EXTVLCOPT:program=7801
http://openwebif.example.com:8001/1:0:1:F49:1470:13E:820890:0:0:0:

I would like to have it redirected or renamed to:

http://streaming.example.com/1:0:1:F49:1470:13E:820890:0:0:0:

Is it possible to do so? How to do so?

I tried in the past (see below, with Caddy1), but I still cannot make my head around this.

Thanks

6. Links to relevant resources:

Since you’re running on a Debian-based distro, I strongly recommend running Caddy as a systemd service instead of with caddy start.

That’s invalid. I think you meant to include a = in there between max-age and the number.

You could do this with this plugin:

But the best solution will definitely be to fix it at the source. Could you run a script to update the files openwebif generates to fix them?

1 Like

Thank you Francis.

I read about the documentation you pointed to me, bit honestly I feel lost on how and where it would need to be implemented.

Unfortunately, even looking at openwebif GitHub, it seems there is no interest to change behavior. Possibly because it is a tool made for local cast/streaming (or most people streams enigma2 through Plex using various middleware and Plex, which seems overkilling to me)…

Are there easy practical examples I can refer to understand how the module would work?

Thanks again

Have you read the README?

Please explain what you don’t understand.

Sure, I did. But honestly I do not know where to start when I read:

This module has Caddyfile support. It registers the replace directive. Make sure to order the handler directive in the correct place in the middleware chain

  1. How to install/enable this module?
  2. Where is “the correct place” in my Caddyfile?
  3. Should it be in the section of streaming.example.com or decoder.example.com?
  4. Should I basically use regex to change “decoder.example.com:8001” to “streaming.example.com”?

Apologies for the dumb questions.

Thanks

1 Like

Either with xcaddy or by grabbing a build from Download Caddy.

As described in the README at GitHub - caddyserver/replace-response: Caddy module that performs replacements in response bodies you need to set the order for the replace directive, then you can use it anywhere within your site blocks.

You put it in whichever site responds with the content you want to transform.

Probably? Try it out and play with it.