Caddy: Proxy subdomains

Created on 18 Apr 2016  路  2Comments  路  Source: caddyserver/caddy

I don't think that is it a bug. But I can't find a good example for this use case.

1. What version of Caddy are you running (caddy -version)?

0.8.2

2. What are you trying to do?

Proxy subdomain to different servers

3. What is your entire Caddyfile?

:443
proxy subdomain.example.de/ someserver:8080 {
    proxy_header Host {host}
    proxy_header X-Real-IP {remote}
    proxy_header X-Forwarded-Proto {scheme}
}
proxy subdomainA.example.de/ someserver:8000 {
    proxy_header Host {host}
    proxy_header X-Real-IP {remote}
    proxy_header X-Forwarded-Proto {scheme}
}
tls {
    max_certs 10
}
log /var/log/caddy.log
gzip

4. How did you run Caddy (give the full command and describe the execution environment)?

As a Docker container linked with docker-compose to other containers.

5. What did you expect to see?

The specified servers (someserver)

6. What did you see instead (give full error messages and/or log)?

404 Not Found

Most helpful comment

You want something like this instead:

subdomain.example.de {
    proxy / someserver:8080 {
        proxy_header Host {host}
        proxy_header X-Real-IP {remote}
        proxy_header X-Forwarded-Proto {scheme}
    }
    log /var/log/caddy.log
    gzip
}

subdomainA.example.de {
    proxy / someserver:8000 {
        proxy_header Host {host}
        proxy_header X-Real-IP {remote}
        proxy_header X-Forwarded-Proto {scheme}
    }
    log /var/log/caddy.log
    gzip
}

In other words, you're serving two different sites. Most directives only take a base path as the first argument, not comparing on the whole URI.

All 2 comments

You want something like this instead:

subdomain.example.de {
    proxy / someserver:8080 {
        proxy_header Host {host}
        proxy_header X-Real-IP {remote}
        proxy_header X-Forwarded-Proto {scheme}
    }
    log /var/log/caddy.log
    gzip
}

subdomainA.example.de {
    proxy / someserver:8000 {
        proxy_header Host {host}
        proxy_header X-Real-IP {remote}
        proxy_header X-Forwarded-Proto {scheme}
    }
    log /var/log/caddy.log
    gzip
}

In other words, you're serving two different sites. Most directives only take a base path as the first argument, not comparing on the whole URI.

Okay, I got it. Thanks!

Was this page helpful?
0 / 5 - 0 ratings