Caddy to use HTTPS on different port

This isn’t working, any idea why? (caddy will not start):

naganu.com {
        log /var/log/caddy/naganu-com.log {
                rotate {
                size 1  # Rotate after 1 MB
                age  7  # Keep log files for 7 days
                keep 1  # Keep at most 1 log files
                }
        }
        header / {
                Strict-Transport-Security "max-age=31536000"
                X-XSS-Protection "1; mode=block"
                X-Content-Type-Options "nosniff"
                X-Frame-Options "DENY"
        }
        tls {
                key_type rsa4096
        }
        proxy / http://127.0.0.1:3000 {
                transparent
        }
        proxy /api/v1/streaming http://127.0.0.1:4001 {
                transparent
        }
        errors {
                500 501 502 503 504 500.html
        }
}

naganu.com:4000 {
        log /var/log/caddy/naganu-com-4000.log {
                rotate {
                size 1  # Rotate after 1 MB
                age  7  # Keep log files for 7 days
                keep 1  # Keep at most 1 log files
                }
        }
       header / {
                Strict-Transport-Security "max-age=31536000"
                X-XSS-Protection "1; mode=block"
                X-Content-Type-Options "nosniff"
                X-Frame-Options "DENY"
        }
        tls {
                key_type rsa4096
        }
        proxy / http://127.0.0.1:4001 {
                transparent
        }
}

What’s the error message you get?

Getting:

Apr 07 20:17:22 ferenginar systemd[1]: caddy.service: Start request repeated too quickly.
Apr 07 20:17:22 ferenginar systemd[1]: Failed to start Caddy HTTP/2 web server.

And:

Apr 07 20:22:07 ferenginar systemd[1]: Network Service is not active.
Apr 07 20:22:07 ferenginar systemd[1]: Dependency failed for Wait for Network to be Configured.
-- Subject: Unit systemd-networkd-wait-online.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit systemd-networkd-wait-online.service has failed.
--
-- The result is dependency.
Apr 07 20:22:07 ferenginar systemd[1]: systemd-networkd-wait-online.service: Job systemd-networkd-wait-online.service/start failed with result 'dependency'.
Apr 07 20:22:07 ferenginar systemd[1]: caddy.service: Start request repeated too quickly.
Apr 07 20:22:07 ferenginar systemd[1]: Failed to start Caddy HTTP/2 web server.
-- Subject: Unit caddy.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit caddy.service has failed.

@Fastidious can you provide the output of journalctl -u caddy.service ?

Or you can also edit /etc/systemd/system/caddy.service and change line 20

https://github.com/mholt/caddy/blob/master/dist/init/linux-systemd/caddy.service#L20

to -log /tmp/caddy.log or wherever you want to put. You need to see this output one way or another to see why Caddy is failing to start

1 Like

Assuming you’ve got a network connection up and running on the host (this service normally fails if it can’t configure any interfaces), I’ve seen this happen before when the system was running NetworkManager (or some other network daemon) instead of systemd-networkd. What’s your network manager?

If I define any log directive inside the Caddyfile, I get exactly the same error message.
I solved it by simply removing the -log stdout from the ExecStart and define the logging inside the Caddyfile.

Note that the CLI -log flag and the Caddyfile log directive do not log the same thing.

The -log flag is for process logging that occurs during Caddy runtime. The log directive is effectively an access log for the webserver.

@Whitestrake I have this issue currently only at one particular server (running Ubuntu 16 LTS). … And “solved” does not necessarily mean it’s the right or best way but it solves the problem of not being able to start caddy as service with an enabled logging directive. If I run caddy with the same arguments as in the systemd script /usr/local/bin/caddy -log stdout -agree=true -conf=/etc/caddy/Caddyfile -root=/var/tmp on the terminal everything works fine.
I hope this clarifies my previous “solved” posting. I don’t wanted to state that this solution is perfect - because it isn’t - but it works temporarily (for me).

No worries, I just wanted to make sure there was no ambiguity - I was worried you might have thought that the log directive was the same and you weren’t losing anything by removing the flag. If the process log isn’t necessary and it’s causing some blocking issue, absolutely removing it is a fine workaround.

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