1. The problem I’m having:
I have a working Caddyfile configuration that helps me host multi-tenant application with subdomain approach. I wish to know if there’s a way to allow customers to use the sub-directory approach as well.
In a nutshell, with my configuration:
-
Users can create:
subdomain.jatra.app
and run my SaaS on it by mapping subdomain:community.customer.com
tosubdomain.jatra.app
using CNAME. -
I want to allow an option to allow hosting on
customer.com/community/
where the my app will load fromsubdomain.jatra.app
.
PS: I’m not sure how to explain this. I am looking to offer both subdirectory and subdomain options for my SaaS; and I’m not even sure if this is possible.
2. Error messages and/or full log output:
N/A
3. Caddy version:
2.7.6
4. How I installed and ran Caddy:
Simply followed these steps: Install — Caddy Documentation
a. System environment:
Distributor ID: | Ubuntu |
---|---|
Description: | Ubuntu 22.04.4 LTS |
Release: | 22.04 |
Codename: | jammy |
b. Command:
N/A
c. Service/unit/compose file:
N/A
d. My complete Caddy config:
{
on_demand_tls {
ask http://localhost:5001/caddy/ask
interval 2m
burst 5
}
# Global logging settings
log {
output file /var/log/caddy/access.log {
roll_size 100mb # Max size of a log file before it's rolled
roll_keep 5 # Number of rolled files to keep
roll_keep_for 720h # Duration to keep rolled files
}
}
}
:5001 {
root * /home/forge/jatra.app/public
php_fastcgi unix//run/php/php8.3-fpm.sock
try_files {path} /index.php?{query}
file_server
}
# Main domain and all subdomains
https://jatra.app, https://*.jatra.app {
tls {
on_demand
}
root * /home/forge/jatra.app/public
encode gzip
file_server
php_fastcgi unix//run/php/php8.3-fpm.sock
header {
# Ensure the header specifying the original host is passed to PHP
X-Original-Host {host}
}
}
# Catch-all for any other domain (for your customer's custom domains)
https:// {
tls {
on_demand
}
root * /home/forge/jatra.app/public
encode gzip
file_server
php_fastcgi unix//run/php/php8.3-fpm.sock
header {
# Ensure the header specifying the original host is passed to PHP
X-Original-Host {host}
}
}
5. Links to relevant resources:
N/A