Different redirection

Hi all,
this is the first time I’m trying to run this server and it seems

1. Caddy version (caddy version):

v2.3.0 h1:fnrqJLa3G5vfxcxmOH/+kJOcunPLhSBnjgIvjXV/QTA=

2. How I run Caddy:

I am using caddy in docker.

a. System environment:

$ lsb_release -a
No LSB modules are available.
Distributor ID: Raspbian
Description: Raspbian GNU/Linux 10 (buster)
Release: 10
Codename: buster

$ docker -v
Docker version 20.10.2, build 2291f61

b. Command:

docker run \
 --restart=unless-stopped \
 --init -d \
 --name="caddy" \
 -v /home/pi/Homeassistant/config:/config \
 -v /home/pi/Caddy/Caddyfile:/etc/caddy/Caddyfile \
 -v /home/pi/Caddy/data:/data  \
 -p 9000:9000 \
 -e "TZ=Europe/Rome" \
 --net=host \
caddy:latest

c. Service/unit/compose file:

paste full file contents here

d. My complete Caddyfile or JSON config:

(https_header) {
  header {
    Strict-Transport-Security "max-age=31536000; includeSubdomains"
    X-XSS-Protection "1; mode=block"
    X-Content-Type-Options "nosniff"
    X-Frame-Options "SAMEORIGIN"
    Referrer-Policy "same-origin"
  }
}


https://pippo.parecchio.org:123 {
  import https_header
  reverse_proxy http://192.168.1.10:124
  log {
    output file /var/log/pippoparecchio.log {
      roll_size 10
      roll_keep 5
      roll_keep_for 720h
      }
    }
}

3. The problem I’m having:

4. Error messages and/or full log output:

5. What I already tried:

at the moment I have other docker services on port 1 , 2 , 3, ecc.
I would like to reach this services when I connect to
https://pippo.parecchio.org:123/1
https://pippo.parecchio.org:123/2
https://pippo.parecchio.org:123/3
https://pippo.parecchio.org:123/ecc

how should I have to configure my caddy server in order to obtain this result?

thanks for the help

Leo

You need to publicly expose ports 80 and 443 to make use of Caddy’s Automatic HTTPS. Your Docker run command only maps port 9000 to the host, but not ports 80 and 443 (or 123 for that matter).

@francislavoie I think is not clear what I would like to obtain
My server on https on 9000 port works great.
What I would like to optain is to see as follows.
When I connect (from outside my home) to https://pippo.parecchio.org:123/1/ I would like to see the page that that I see (at home) browsing http://192.168.1.10:1/

How to configure the caddyfile?

And so on.
Hope now is more clear

Like I said, you won’t be able to get HTTPS on port 123. The HTTPS port is 443. ACME challenges are done on ports 80 and 443 unless you use the DNS challenge.

Also, you should be aware that low ports (under 1024) are typically reserved for other kinds of services, so I recommend using higher port numbers for applications.

I think you might be looking for the handle_path directive to decide how to handle your requests with different path suffixes, but I would recommend using subdomains for routing instead of subpaths. Read more here:

@francislavoie , I’m really thankful for your support but I see you don’t understand me.
Please, forget about the SSL part (I’ve already managed to configure it) and don’t focus on the number of the ports (I will change them, the one I’ve indicated are only for example).
Let’s do differently.
In the following situation:

How should I write the Caddyfile in order to access server1 if I write http://www.myFQDN.com:8080/1/,
access the server2 if I write http://www.myFQDN.com:8080/2/, and so on…

Hope now is more clear my request. :slight_smile:

PS (sorry I’ve forgot to write, but the square in the middle is the caddy server that I have to configure)

Like I said, you’d use handle_path.

www.myFQDN.com {
	handle_path /1/* {
		reverse_proxy 192.168.0.10:8080
	}

	handle_path /2/* {
		reverse_proxy 192.168.0.11:8080
	}

	handle {
		# Fallback if nothing else matched
	}
}

But to reiterate, I recommend using subdomains whenever possible instead of subpath proxying if these are services you didn’t write yourself, see the subfolder problem link above.

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