Config optimization

1. Caddy version (caddy version):

2.4.3

2. How I run Caddy:

Installed using apt and started using systemd.

a. System environment:

Debian 11

b. Command:

systemctl start caddy

c. Service/unit/compose file:

[Unit]
Description=Caddy
Documentation=https://caddyserver.com/docs/
After=network.target network-online.target
Requires=network-online.target

[Service]
Type=notify
User=caddy
Group=caddy
ExecStart=/usr/bin/caddy run --environ --config /etc/caddy/Caddyfile
ExecReload=/usr/bin/caddy reload --config /etc/caddy/Caddyfile
TimeoutStopSec=5s
LimitNOFILE=1048576
LimitNPROC=512
PrivateTmp=true
ProtectSystem=full
AmbientCapabilities=CAP_NET_BIND_SERVICE

[Install]
WantedBy=multi-user.target

d. My complete Caddyfile or JSON config:

domain.com {
        bind AAA.BBB.CCC.DDD
        reverse_proxy https://EEE.FFF.GGG.HHH {
                lb_policy first
                lb_try_duration 2s
                lb_try_interval 250ms
                health_uri /
                health_interval 2s
                health_timeout 2s
                transport http {
                        dial_timeout 10s
                        response_header_timeout 10s
                        expect_continue_timeout 10s
                        tls
                        tls_insecure_skip_verify
                        tls_timeout 10s
                        keepalive off
                        compression off
                }
        }
        handle_errors {
                encode gzip
                root * /var/caddy
                file_server {
                        index noroute.html
                }
        }
}

3. The problem I’m having:

I have finally found a working config for what I want to do: I want to have a reverse proxy that will display an error page when the backend server is down.

What I need help with is optimizing the configuration file. Is anything missing? Can something be left out? Are timeouts set to sane values?

I do not need it for one specific site/backend project (like NextCloud or anything of the sorts) so I need it to be compatible with most things out of the box.

What can be optimized, if anything? Thanks :slight_smile:

I have removed those 3 lines and it seems to be responding faster with the error page. I figured it wasn’t needed.

Any other suggestions? :slight_smile:

I added this header as well:

header_up X-Real-IP {remote}

Anything else I can tweak?

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