Caddy ssl with cloudflare on different port

1. The problem I’m having:

i am trying to setup caddy with cloudflare origin ssl on a different ssl port. Trying to setup only ssl website, but if possible a non-ssl website too on a different http port. I tried remove my domain from config and tried simple :2096 too but that also fails.

2. Error messages and/or full log output:

-- Logs begin at Sun 2023-12-31 01:29:04 EST, end at Sun 2023-12-31 09:29:18 EST. --
Dec 31 09:26:54 vps.exo.com systemd[1]: Failed to start Caddy.
Dec 31 09:26:54 vps.exo.com systemd[1]: caddy.service: Failed with result 'exit-code'.
Dec 31 09:26:54 vps.exo.com systemd[1]: caddy.service: Main process exited, code=exited, status=1/FAILURE
Dec 31 09:26:54 vps.exo.com caddy[4439]: Error: loading initial config: loading new config: http app module: start: listening on :80: listen tcp :80: bind: address already in use
Dec 31 09:26:54 vps.exo.com caddy[4439]: {"level":"info","ts":1704032814.2005305,"logger":"tls.cache.maintenance","msg":"stopped background certificate maintenance","cache":"0xc0004d6080"}
Dec 31 09:26:54 vps.exo.com caddy[4439]: {"level":"info","ts":1704032814.2003343,"logger":"http.log","msg":"server running","name":"srv0","protocols":["h1","h2","h3"]}
Dec 31 09:26:54 vps.exo.com caddy[4439]: {"level":"info","ts":1704032814.1971729,"msg":"[INFO][FileStorage:/var/lib/caddy/.local/share/caddy] Lock for 'storage_clean' is stale (created: 2023-12-30 16:25:05.984950364 -0500 EST, last update: 2023-12-30 16:25:05.984950364 -0500 EST); removing then retrying: /var/lib/caddy/.local/share/caddy/locks/storage_clean.lock"}
Dec 31 09:26:54 vps.exo.com caddy[4439]: {"level":"info","ts":1704032814.195484,"logger":"http","msg":"enabling HTTP/3 listener","addr":":2096"}
Dec 31 09:26:54 vps.exo.com caddy[4439]: {"level":"info","ts":1704032814.1949952,"logger":"http.auto_https","msg":"enabling automatic HTTP->HTTPS redirects","server_name":"srv0"}
Dec 31 09:26:54 vps.exo.com caddy[4439]: {"level":"warn","ts":1704032814.1947627,"logger":"tls","msg":"stapling OCSP","error":"no OCSP stapling for [cloudflare origin certificate *.exo.com exo.com]: no URL to issuing certificate"}
Dec 31 09:26:54 vps.exo.com caddy[4439]: {"level":"info","ts":1704032814.1915162,"logger":"tls.cache.maintenance","msg":"started background certificate maintenance","cache":"0xc0004d6080"}
Dec 31 09:26:54 vps.exo.com caddy[4439]: {"level":"info","ts":1704032814.1896217,"logger":"admin","msg":"admin endpoint started","address":"localhost:2019","enforce_origin":false,"origins":["//localhost:2019","//[::1]:2019","//127.0.0.1:2019"]}
Dec 31 09:26:54 vps.exo.com caddy[4439]: {"level":"info","ts":1704032814.1571095,"msg":"using provided configuration","config_file":"/etc/caddy/Caddyfile","config_adapter":""}
Dec 31 09:26:54 vps.exo.com caddy[4439]: JOURNAL_STREAM=8:15721573
Dec 31 09:26:54 vps.exo.com caddy[4439]: INVOCATION_ID=030ce34810f34c40a73984a97841a66f
Dec 31 09:26:54 vps.exo.com caddy[4439]: USER=caddy
Dec 31 09:26:54 vps.exo.com caddy[4439]: LOGNAME=caddy
Dec 31 09:26:54 vps.exo.com caddy[4439]: HOME=/var/lib/caddy
Dec 31 09:26:54 vps.exo.com caddy[4439]: NOTIFY_SOCKET=/run/systemd/notify
Dec 31 09:26:54 vps.exo.com caddy[4439]: PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Dec 31 09:26:54 vps.exo.com caddy[4439]: LANG=en_US.UTF-8
Dec 31 09:26:54 vps.exo.com caddy[4439]: os.Getwd=/
Dec 31 09:26:54 vps.exo.com caddy[4439]: runtime.Version=go1.21.5
Dec 31 09:26:54 vps.exo.com caddy[4439]: runtime.GOMAXPROCS=2
Dec 31 09:26:54 vps.exo.com caddy[4439]: runtime.NumCPU=2
Dec 31 09:26:54 vps.exo.com caddy[4439]: runtime.Compiler=gc
Dec 31 09:26:54 vps.exo.com caddy[4439]: runtime.GOARCH=amd64
Dec 31 09:26:54 vps.exo.com caddy[4439]: runtime.GOOS=linux
Dec 31 09:26:54 vps.exo.com caddy[4439]: caddy.Version=v2.7.6 h1:w0NymbG2m9PcvKWsrXO6EEkY9Ru4FJK8uQbYcev1p3A=
Dec 31 09:26:54 vps.exo.com caddy[4439]: caddy.ConfigAutosavePath=/var/lib/caddy/.config/caddy/autosave.json
Dec 31 09:26:54 vps.exo.com caddy[4439]: caddy.AppConfigDir=/var/lib/caddy/.config/caddy
Dec 31 09:26:54 vps.exo.com caddy[4439]: caddy.AppDataDir=/var/lib/caddy/.local/share/caddy
Dec 31 09:26:54 vps.exo.com caddy[4439]: caddy.HomeDir=/var/lib/caddy
Dec 31 09:26:53 vps.exo.com systemd[1]: Starting Caddy...

3. Caddy version:

v2.7.6 h1:w0NymbG2m9PcvKWsrXO6EEkY9Ru4FJK8uQbYcev1p3A=

4. How I installed and ran Caddy:

Official installing in caddy docs for debian stable release.

a. System environment:

debian 11, x86_64, systemd.

b. Command:

systemctl restart caddy 
that is all i use for testing config.

c. Service/unit/compose file:

d. My complete Caddy config:


exo.com:2096 {
        tls /etc/ssl/cert.pem /etc/ssl/key.pem
        # Set this path to your site's directory.
        root * /usr/share/caddy

        # Enable the static file server.
        file_server browse

        # Another common task is to set up a reverse proxy:
        # reverse_proxy localhost:8080

        # Or serve a PHP site through php-fpm:
        # php_fastcgi localhost:9000
}

5. Links to relevant resources:

This is because Caddy tries to set up an HTTP server for HTTP->HTTPS redirects. You can turn this off by adding this to the top of your config:

{
    auto_https disable_redirects
}

Or, just make sure you don’t have another program using port 80, so that Caddy can use it.

Thanks auto_https part fixed for me, and the 80 port is used by other service that’s why i want to run caddy on different ports. what should i add in config to serve http on different port with my same settings?

Then I recommend moving that service off port 80 (to let Caddy use it) then proxy to that service through Caddy (with the reverse_proxy directive). That way you can make use of Caddy’s hostname routing to serve that service, and you can use Caddy’s defaults without messing around.

Or, you can use the http_port and https_port global options in Caddy to change the default ports.

Thank you very much, Happy new year! :slight_smile:

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