I can't convert Caddyflie to caddy 2 format correctly

1. Caddy version (caddy version):

Caddy 2.0.0

2. How I run Caddy:

a. System environment:

Debian 10 X86_64

d. My complete Caddyfile or JSON config:

XXX.XXX.com {
 encode gzip
 tls {
            protocols tls1.2 tls1.3
}
    reverse_proxy 8.8.8.8:12345{
    header_up Host {http.request.host}
    header_up X-Real-IP {http.request.remote}
    header_up X-Forwarded-For {http.request.remote}
    header_up X-Forwarded-Port {http.request.port}
    header_up X-Forwarded-Proto {http.request.scheme}
  }
}
YYY.YYY.com {
 encode gzip
 tls {
           protocols tls1.2 tls1.3
}
    reverse_proxy 8.8.8.8:16789{
    header_up Host {http.request.host}
    header_up X-Real-IP {http.request.remote}
    header_up X-Forwarded-For {http.request.remote}
    header_up X-Forwarded-Port {http.request.port}
    header_up X-Forwarded-Proto {http.request.scheme}
  }
}

3. The problem I’m having:

caddy failed to start. I google this problem but there is no answer. When I used caddy 1 before, it didn’t report an error. The old configuration is as follows:

XXX.XXX.COM {
 gzip
protocols tls1.2 tls1.3
 proxy / 8.8.8.8:12345 {
    websocket
    header_upstream Host {host}
    header_upstream X-Real-IP {remote}
    header_upstream X-Forwarded-For {remote}
    header_upstream X-Forwarded-Port {server_port}
    header_upstream X-Forwarded-Proto {scheme}
  }
}
YYY.YYY.com {
 gzip
protocols tls1.2 tls1.3
 proxy / 8.8.8.8:16789 {
    websocket
    header_upstream Host {host}
    header_upstream X-Real-IP {remote}
    header_upstream X-Forwarded-For {remote}
    header_upstream X-Forwarded-Port {server_port}
    header_upstream X-Forwarded-Proto {scheme}
  }
}

4. Error messages and/or full log output:

run: adapting config using caddyfile: duplicate site address not allowed: '}' in [}] (site block 2, key 0)
start: caddy process exited with error: exit status 1

Hi Penny –

Your Caddyfile appears to be malformed. You can read about the structure of the Caddyfile here: Caddyfile Concepts — Caddy Documentation

Also please use code blocks next time, as the Help template asks. You can also use caddy fmt to make your Caddyfile easy to read.

Thank you for your help, and I corrected the Caddyfile and the template for my question. But I still couldn’t run my caddy, I want to reverse two different domain names to different ports of the same IP address, but caddy always shows duplicate site address not allowed.

Code blocks are with ``` on lines before and after your Caddyfile. It preserves whitespace and uses a monospaced font. You used quote blocks instead.

This is my first question in the community, thanks for your correction, I will pay attention in the future.

Ah - you must have a space before the { in Caddyfiles, otherwise the parser reads { as part of the argument.

Also, these are unnecessary:

header_up X-Forwarded-For {http.request.remote}
header_up X-Forwarded-Proto {http.request.scheme}

Both of those are done for you automatically in Caddy v2.

It’s also unnecessary to configure the protocols. Those are the same as the defaults, so just keep the defaults. If at a later date tls1.4 is added for example, then you’d need to manually configure Caddy to allow that - just let Caddy do what it does best :smile:

2 Likes

Thank you very much!

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