1. Caddy version (caddy version
):
2.3.0
2. How I run Caddy:
I have an Angular SPA deployed to Azure storage account and an ExpressJS API instance deployed to Azure container instance. I use Caddy as a sidecar to automatically get the TLS certificates and as a reverse proxy so that both the Angular SPA and ExpressJS API instance appear to run in the same domain (for security purposes and to avoid CORS).
a. System environment:
Docker
b. Command:
Default command in caddy image.
c. Service/unit/compose file:
- name: caddy
properties:
image: caddy:2.3.0
ports:
- protocol: tcp
port: 443
- protocol: tcp
port: 80
volumeMounts:
- name: caddy-data
mountPath: /data
- name: caddy-config
mountPath: /config
- name: caddyfile
mountPath: /etc/caddy
- name: index
mountPath: /usr/share/caddy
resources:
requests:
cpu: 1.0
memoryInGB: 1.0
volumes:
- name: caddy-data
emptyDir: {}
- name: caddy-config
emptyDir: {}
- name: caddyfile
secret:
Caddyfile: d3d3Lm1hcmtldGVyc2NvbXBhc3MuY29tIHsKICAgIHJldmVyc2VfcHJveHkgLyogaHR0cHM6Ly9tYXJrZXRlcnNjb21wYXNzLmF6dXJlZWRnZS5uZXQKICAgIHJldmVyc2VfcHJveHkgL2FwaSogbG9jYWxob3N0OjMwMDAKCiAgICB0cnlfZmlsZXMge3BhdGh9IHtwYXRofS8gL2luZGV4Lmh0bWwKICAgIGZpbGVfc2VydmVyCn0KCm1jbXZwLmNlbnRyYWx1cy5henVyZWNvbnRhaW5lci5pbyB7CiAgICByZXZlcnNlX3Byb3h5IC8qIGh0dHBzOi8vbWFya2V0ZXJzY29tcGFzcy5henVyZWVkZ2UubmV0CiAgICByZXZlcnNlX3Byb3h5IC9hcGkqIGxvY2FsaG9zdDozMDAwCn0KCg==
- name: index
secret:
index.html: PCFET0NUWVBFIGh0bWwgUFVCTElDICItLy9XM0MvL0RURCBIVE1MIDQuMCBUcmFuc2l0aW9uYWwvL0VOIj4KPGh0bWw+CiAgPGhlYWQ+CiAgICA8dGl0bGU+PC90aXRsZT4KICA8L2hlYWQ+CiAgPGJvZHk+PC9ib2R5Pgo8L2h0bWw+Cg==
d. My complete Caddyfile or JSON config:
www.marketerscompass.com {
reverse_proxy /* https://marketerscompass.azureedge.net
reverse_proxy /api* localhost:3000
try_files {path} {path}/ /index.html
file_server
}
mcmvp.centralus.azurecontainer.io {
reverse_proxy /* https://marketerscompass.azureedge.net
reverse_proxy /api* localhost:3000
}
3. The problem I’m having:
As is typical with SPAs, the initial client-side route request results in a 404 in the browser. I’d prefer to eliminate this 404. To do this, I’ve mounted an empty index.html to the caddy container and attempted to use try_files to load it. However, I think the fact that the reverse_proxy also matches it is causing issues. I’m not really sure, to be honest.
4. Error messages and/or full log output:
N/A
5. What I already tried:
I’ve scoured this forum and stackoverflow for tips, but my use case seems to be unique in that I’m not actually serving the Angular SPA from Caddy, only reverse proxying to it.
6. Links to relevant resources:
Thanks for any assistance!