🌐Custom Domain support

Our SaaS module supports custom domains, allowing tenants to connect their own branded domains (e.g., clientdomain.com) to access their tenant space.

⚠️ Automatic support for custom domains is only available on dedicated servers or VPS environments, as it requires direct web server configuration. For cPanel, enabling Addon domain with API access to addon domain will be enough.


βš™οΈ Requirements

To enable custom domain routing and automatic resolution:

  • The SaaS must be hosted on a dedicated server or VPS.

  • You must have root access to configure Nginx or Apache2.

  • Tenants must correctly configure their DNS A record pointing to your server's IP which will be sent via email for the tenant.

  • SaaS public directory should be consistent for all domains (e.g., /srv/yourDomain.com/public).


πŸš€ What Happens Automatically?

  • Once your web server is configured, any tenant that maps a custom domain will be automatically routed to the correct application entry point.

  • All tenants share the same codebase.

πŸ’‘ Note: If you don't have wildcard domain routing configured, you can download a set of instructions which will give you instructions on how to download and run an automated shell script to add the necessary configuration for each tenant.

Simply click the "Download Instructions" action on the Tenants list page to get started.


πŸ“„ Web Server Configuration

Below are the configurations for Nginx and Apache2 to support wildcard/catch-all domain routing.


1. Update Default Server Block

Open the default server block file:

sudo nano /etc/nginx/sites-available/default

Replace or update it with:

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    server_name _;  # Catch-all for any domain

    root /srv/yourDomain.com/public;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-Content-Type-Options "nosniff";

    index index.php;
    charset utf-8;

    access_log /var/log/nginx/vhost_$host.access.log;
    error_log  /var/log/nginx/vhost_$host.error.log;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

    location ~ ^/index\.php(/|$) {
        include fastcgi_params;
        fastcgi_pass unix:/var/run/php/php8.2-fpm.sock; # Adjust PHP version
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        fastcgi_hide_header X-Powered-By;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}

2. Configure Dynamic Logging

Open /etc/nginx/nginx.conf:

sudo nano /etc/nginx/nginx.conf

Add this inside the http block:

log_format vhost '$host $remote_addr - $remote_user [$time_local] '
                 '"$request" $status $body_bytes_sent '
                 '"$http_referer" "$http_user_agent"';

3. Test and restart Nginx

sudo nginx -t
sudo systemctl restart nginx

🟦 Apache2 Configuration

Apache requires enabling wildcard domain support in its VirtualHost setup.

1. Create a Catch-All Virtual Host

Open your default config file:

sudo nano /etc/apache2/sites-available/000-default.conf

Update it with:

<VirtualHost *:80>
    ServerName _default_

    # DocumentRoot should point to your Laravel public folder
    DocumentRoot /srv/yourDomain.com/public

    # Custom dynamic logging based on the domain name
    CustomLog "|/usr/bin/tee -a /var/log/apache2/vhost_%v.access.log" vhost_combined
    ErrorLog /var/log/apache2/vhost_%v.error.log

    <Directory /srv/yourDomain.com/public>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>

    # Pass PHP scripts to PHP-FPM (adjust sock path accordingly)
    <FilesMatch \.php$>
        SetHandler "proxy:unix:/run/php/php8.2-fpm.sock|fcgi://localhost"
    </FilesMatch>
</VirtualHost>

Replace /srv/yourDomain.com/public with your actual Laravel public path.

2. Enable Required Apache Modules

sudo a2enmod rewrite proxy_fcgi setenvif
sudo systemctl restart apache2

Last updated