Search code examples
caddycaddyfile

Change both http and https port on caddy


I'm having trouble setting a custom http and https port on caddy in my Caddyfile and could not find an answer using google and stackoverflow

I can set a custom http port like this :

http://example.com:2015

but I can't set a custom https port

http://example.com:2015
https://example.com:2016

as caddy only reads the first line as valid.

Starting the file with https://example.com:2016 will try to bind http to port 80 which is already taken

I simply want to bind http to port 2015 and https to port 2016

Here is my current Caddyfile:

http://example.com:2015
https://example.com:2016
gzip
log access.log
basicauth / username password
filemanager / /path {
    database dbname.db
    no_auth
}

thank you for your time :)


Solution

  • If you are using multiple hosts

    http://example.com:2015 {
    tls off
    gzip
    log access.log
    basicauth / username password
     filemanager / /path {
     database dbname.db
     no_auth
     }
    }
    
    https://example.com:2016 {
    tls self_signed
    gzip
    log access.log
    basicauth / username password
     filemanager / /path {
     database dbname.db
     no_auth
     }
    }
    

    If you wish for Caddys Automagic HTTPS you will need to use 443 but if you want to supply your own cert or self_sign (or us DNS challenge) then you should be ok.

    Also well worth checking out https://caddy.community/