1. Caddy version (caddy version
):
v2.1.1 h1:X9k1+ehZPYYrSqBvf/ocUgdLSRIuiNiMo7CvyGUQKeA=
(Docker image: caddy/latest)
2. How I run Caddy:
I run Caddy as one of the containers via docker-compose. It serves as the reverse proxy for my PHP-apache container.
a. System environment:
- macOS v10.15.5
- Docker Engine 20.10.2
b. Command:
N/A
c. Service/unit/compose file:
version: "3.9"
# User Defined Network
networks:
static-host:
driver: bridge
ipam:
driver: default
config:
- subnet: 172.10.0.0/24
# Service Containers
services:
# Caddy2
caddy:
restart: unless-stopped
hostname: caddy
image: caddy:latest
networks:
static-host:
ipv4_address: 172.10.0.10
ports:
- "80:80"
- "443:443"
volumes:
- $PWD/data/caddy/data:/data
- $PWD/data/caddy/config:/config
- $PWD/data/caddy/Caddyfile:/etc/caddy/Caddyfile:ro
# Web Server (Apache2 + PHP)
php-apache:
restart: unless-stopped
hostname: php-apache
build:
context: $PWD/build/php-apache
networks:
static-host:
ipv4_address: 172.10.0.11
ports:
- "8080:80"
volumes:
- $PWD/data/php-apache/www:/var/www
d. My complete Caddyfile or JSON config:
(mkcert) {
tls /data/certs/wildcard.localhost.pem /data/certs/wildcard.localhost-key.pem
}
# PHP-Apache
www.localhost {
import mkcert
reverse_proxy php-apache:80
}
portfolio.www.localhost {
import mkcert
rewrite / /portfolio_web/{uri}
reverse_proxy php-apache:80 {
header_up Host portfolio.www.localhost
header_up X-Forwarded-Proto https
}
}
3. The problem I’m having:
- I would like to serve the website
https://portfolio.www.localhost/*
under the root of/var/www/html/portfolio_web/
of PHP-apache container via reverse proxy, without the subdirectory in URL. - The default root for PHP-apache container is
/var/www/html
forhttps://www.localhost/
4. Error messages and/or full log output:
N/A
5. What I already tried:
I tried rewrite
, redir
and route
directives but failed to achieve what I want.
The above attempts changed the URL from https://portfolio.www.localhost/*
to https://www.localhost/portfolio_web/*
.
6. Links to relevant resources:
N/A