Messed up: Need suggestions for recovery

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:

  1. Users can create: subdomain.jatra.app and run my SaaS on it by mapping subdomain: community.customer.com to subdomain.jatra.app using CNAME.

  2. I want to allow an option to allow hosting on customer.com/community/ where the my app will load from subdomain.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

Totally depends on the application:

If the application supports it (for example, I think WordPress lets you specify a base URL, Jellyfin does too), then you’re good. If not, it’s very very difficult to do correctly from outside the application.

1 Like

Yeah - much easier if the customer points a subdomain to your server like community.customer.com and then you can handle that with On-Demand TLS pretty easily.

1 Like

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