Migrate multiple sites w/ reverse proxy in v2 (proxy to subdir)

1. Caddy version (caddy version):

v2.2.0 h1:sMUFqTbVIRlmA8NkFnNt9l7s0e+0gw+7GPIrhty905A=

2. How I run Caddy:

caddy2 run --config Caddyfile

a. System environment:

AWS Linux 2 (essentially Centos 7)
I’m proxying to multiple domains to apps running under tomcat on port 8080

d. My complete Caddyfile or JSON config:

https://site-one.com {
    gzip
    errors
header / {
    Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
    X-Content-Type-Options "nosniff"
    Content-Security-Policy "upgrade-insecure-requests"
    Referrer-Policy "strict-origin-when-cross-origin"
    Access-Control-Allow-Origin "*"
    Cache-Control "public, max-age=15, must-revalidate"
    Feature-Policy "accelerometer 'none'; ambient-light-sensor 'none'; autoplay 'self'; camera 'none'; encrypted-media 'none'; fullscreen 'self'; geolocation 'none'; gyroscope 'none'; magnetometer 'none'; microphone 'none'; midi 'none'; payment 'none'; picture-in-picture *; speaker 'none'; usb 'none'; vr 'none'"
}
proxy / http://localhost:8080/site-one {
    transparent
    without /site-one
    }
log / /var/log/caddy/site-one.log "{combined}"
}

https://site-two.com {
    gzip
    errors
header / {
    Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
    X-Content-Type-Options "nosniff"
    Content-Security-Policy "upgrade-insecure-requests"
    Referrer-Policy "strict-origin-when-cross-origin"
    Access-Control-Allow-Origin "*"
    Cache-Control "public, max-age=15, must-revalidate"
    Feature-Policy "accelerometer 'none'; ambient-light-sensor 'none'; autoplay 'self'; camera 'none'; encrypted-media 'none'; fullscreen 'self'; geolocation 'none'; gyroscope 'none'; magnetometer 'none'; microphone 'none'; midi 'none'; payment 'none'; picture-in-picture *; speaker 'none'; usb 'none'; vr 'none'"
}
proxy / http://localhost:8080/site-two {
    transparent
    without /site-two
    }
log / /var/log/caddy/site-two.log "{combined}"
}

3. The problem I’m having:

I cannot find the desired config to make this work under Caddy v2

5. What I already tried:

I’ve got the config working for a single site only:

site-one.com {
encode gzip
import headers
reverse_proxy localhost:8080
log {
output file /var/log/caddy/site-one.log
}
}

it took way to long to find the answer to this (around 20 hours!), but I finally got it to work by doing a rewrite before reverse proxy. note that this only works for single subdirs. see the subfolder problem

my config now:
site-one.com {
encode gzip
import headers
rewrite * /site-one{uri}
reverse_proxy localhost:8080
log {
output file /var/log/caddy/site-one.log
}
}

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