Caddy initial config question

my saas app have main domain and subdomain and custome domain
please help how i can config Caddy??

I moved your post to its own topic.
Please fill out the forum template and provide as much information as possible.
Thank you

You can try configuration like this

{
        email your@email.com
}

*.maindomain.local maindomain.local {
        encode gzip 
        root * /usr/local/www/public   # /usr/local/www/public is where your web root 
        # php_fastcgi 127.0.0.1:9000   or  php_fastcgi unix//run/php/php8.1-fpm.sock
        # depend on you, uncomment  # to use

        # forbidden access to /privatedate/ and install.php directly, respond with HTTP 403 Forbidden  
        @forbidden path /privatedata/* /install.php   
        handle @forbidden {
                respond * 403
        }

         # reverse_proxy subdomain.maindomain.local to your other server located in your local network at ip 192.168.1.100. It must be accessible locally when your browse http://192.168.1.100
        @subdomain host subdomain.maindomain.local
        handle @subdomain {   
               reverse_proxy 192.168.1.100 {  
                      rewrite /
                      header_up Host {http.reverse_proxy.upstream.hostport}
               }
        }

       #when accessing  maindomain.com/folder1/ , following take place
        handle /folder1/* {
                respond "Hello folder1"
        }

        file_server
        try_files {path} {path}/ /index.php
}

www.maindomain.local {
        # redirection  https://www.mainldomain.local to https://maindomain.local
        redir https://maindoman.local    
}

# custome domain https://custome.domain.local  will be as follow
custome.domain.local {
        root * /usr/local/www/public
        file_server
}

The above should cover what you ask.
Link below will explain it mean, and how to use it.

Cheers

# custome domain https://custome.domain.local  will be as follow
custome.domain.local {
        root * /usr/local/www/public
        file_server
}

i have unlimied custome domain each customer can create munti custome domain .
do custome.domain.local just for one custome domain ?

another question is , do work for all subdomain * wildcard ?

    @subdomain host subdomain.maindomain.local
    handle @subdomain {   
           reverse_proxy 192.168.1.100 {  
                  rewrite /
                  header_up Host {http.reverse_proxy.upstream.hostport}
           }
    }

Please fill out the help topic template, as per the forum rules.

I’d recommend reading this guide fully:

after two day search i cant fix probleam in *.sample.com and custom domain2.com please help me

this my caddy file . just work in sample.com

sample.com *.sample.com {

        root * /var/www/html/public
        # Enable the static file server.
        file_server
        encode gzip zstd
        tls dddddd@gmail.com
        php_fastcgi unix//run/php/php8.0-fpm.sock
}

www.sample.ir {
       redir https://sample.com
}

Wildcard certificates require the DNS challenge, as stated in “Wildcard certificates” in Automatic HTTPS — Caddy Documentation and other places, including the wiki/guide, which is the topic you originally posted your post and @matt recommended you read in Caddy initial config question - #6 by matt

Are you sure php_fastcgi point it to correctly ?
Remove wildcard, and php_fastcgi , does the page load correctly with the code below ?

sample.com {
        root * /var/www/html/public
        file_server
        encode gzip zstd
        tls your@email.com
        respond "Hello World!"
        #php_fastcgi unix//run/php/php8.0-fpm.sock
}

www.sample.ir {
       redir https://sample.com
}

i sovled dns challenge for domain and subdomain with cloadflare .

but have one problem in custome domain .

becuase each customer have self domain and subdomain . and i want to serve all thing in caddy .

please help me in this type of custome domain .

I ask again.

Please fill out the help topic template, as per the forum rules.

There’s a lot of gaps in our understanding of what you’re trying to do, and filling out the help topic template would clear a lot of that up for us.

can you explain what does this mean ?
Is my example given above able to help you ?

i have central domain (sample.com) after registration create one subdomain for each user like (ada.sample.com)

then user can change ada.sample.com to >>> doain.com or my.doain.com or other user can use self domain like dxa.com , … unlimited custome domain or subdomains

How to define the settings of these states?

sample.com *.sample.com {

	root * /var/www/public
	file_server
	encode gzip 
	php_fastcgi unix//run/php/php8.0-fpm.sock

	tls {
		dns cloudflare "_H_vQajBjTvG_G-nJtF8UdZPr0kR8i8"
		resolvers 1.1.1.1
	}

}

in same this tutorial Serving tens of thousands of domains over HTTPS with Caddy use this syntx

https:// {
    tls {
        on_demand
    }
    reverse_proxy localhost:9000
}

Now how do you combine these two?

So you want to have both a wildcard cert for your main domain, plus On-Demand TLS for domains your customers point to your server?

You’ll need two sites, one with https:// and on_demand (and you must set up an ask endpoint for On-Demand TLS – see the docs – otherwise you’re at risk of denial of service attacks), and the other site with your main + wildcard domains.

You need to enable the DNS challenge for Caddy to issue a wildcard certificate – that’s a requirement of ACME. It looks like you’re doing that with CloudFlare, so that’s good :+1:

It looks like you just posted your CloudFlare API. You’ll want to revoke that API key as soon as possible, otherwise anyone could start doing bad things with your account. You must keep your API key secret.


But again. Please, follow the forum rules, as we ask.

You must fill out the help topic template.

i solve many problem in php-fpm prmission in www-data and cady user , about this this in docs not exists ant document !!
so . custom domain get ssl but not connect to main website there are splice another website and not related to center domain

It’s not Caddy’s job to document how to run PHP. That’s out of scope.

I’m not sure what you mean.


Once again, and this is the last time I’ll ask before I lock this topic, fill out the help topic template. You’re not following the rules.

This topic was automatically closed after 29 days. New replies are no longer allowed.