Reverse proxy to unix socket in JSON config

1. Caddy version (v2.2.1):

2. How I run Caddy:

using api http://127.0.0.1:2019/config/

a. System environment:

ubuntu 18

b. Command:

curl --header "Content-Type: application/json" \
  --request PATCH \
  --data '{
   "apps":{
      "http":{
         "servers":{
            "srv0":{
               "listen":[
                  ":443"
               ],
               "routes":[
                  {
                     "match":[
                        {
                           "host":[
                              "sub.domain1.tls"
                           ]
                        }
                     ],
                     "handle":[
                        {
                           "handler":"reverse_proxy",
                           "upstreams":[
                              {
                                 "dial":"unix//path/to/sub.domain1.sock"
                              }
                           ]
                        }
                     ]
                  }
               ]
            }
         }
      }
   }
}' \
  http://localhost:2019/config/

c. Service/unit/compose file:

paste full file contents here

d. My complete Caddyfile or JSON config:

{
   "apps":{
      "http":{
         "servers":{
            "srv0":{
               "listen":[
                  ":443"
               ],
               "routes":[
                  {
                     "match":[
                        {
                           "host":[
                              "sub.domain1.tls"
                           ]
                        }
                     ],
                     "handle":[
                        {
                           "handler":"reverse_proxy",
                           "upstreams":[
                              {
                                 "dial":"unix//path/to/sub.domain1.sock"
                              }
                           ]
                        }
                     ]
                  }
               ]
            }
         }
      }
   }
}

3. The problem I’m having:

i am using gunicorn socket. i have done in caddy file using socket file but i cant in json config.

Working caddyfile arebellow.
thank you for your help.


# /etc/caddy/Caddyfile

sub.domain1.tls { 
    reverse_proxy unix//path/to/sub.domain1.sock 
}

4. Error messages and/or full log output:

5. What I already tried:

6. Links to relevant resources:

If your Caddyfile works, then you can simply use the caddy adapt command to get the underlying JSON config for it.

2 Likes

Thank you francis,
i didn’t know there was an adapter, it’s very useful.
I leave the command example below for those who don’t know likeme
thanks again

caddy adapt --config /etc/caddy/Caddyfile --pretty

2 Likes

Yep! The Caddyfile itself is an adapter to JSON. It’s just some syntax sugar to make using Caddy easier, but Caddy always uses JSON under the hood.

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