Heroku Reverse Proxy

1. Caddy version (caddy version):

2.5.1

2. How I run Caddy:

caddy start

a. System environment:

Ubuntu, dockerfile

b. Command:

caddy start

c. Service/unit/compose file:

FROM ubuntu

RUN apt update -y\
&& apt install -y debian-keyring debian-archive-keyring apt-transport-https curl gettext-base\
&& curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg\
&& curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | tee /etc/apt/sources.list.d/caddy-stable.list\
&& apt update -y\
&& apt install caddy -y

COPY Caddyfile /etc/caddy/Caddyfile
COPY entrypoint.sh /entrypoint.sh

RUN chmod +x /entrypoint.sh

CMD ["/entrypoint.sh"]

d. My complete Caddyfile or JSON config:

${DOMAIN}{
  reverse_proxy * ${UPSTREAM} {
    header_up Host {http.reverse_proxy.upstream.hostport}
    header_up X-Forwarded-Host {host}
  }
}

3. The problem I’m having:

I keep getting 503 service unavaiable

4. Error messages and/or full log output:

5. What I already tried:

So i tried to create heroku reverse proxy.
But i keep getting 503 service unavaiable from heroku when i accessed the sub/domain. Idk why!l

Check my repo link bellow you will see Dockerfile, entrypoint, and Caddyfile

6. Links to relevant resources:

Are you sure you don’t mean {$DOMAIN} and {$UPSTREAM} placeholders? Looks like you’re trying to write a shell script here.

Also, you skipped step 4, so our guess is as good as yours without logs.

1 Like

Why are you writing your own Dockerfile like that? Why not just use the official Caddy docker image? See Docker Hub

As Matt said, I don’t think you’re using the correct syntax for environment variables. See the docs:

Also, make sure you have a space before the opening { for your site block. Whitespace is important.

Try this:

{$DOMAIN} {
  reverse_proxy {$UPSTREAM} {
    header_up Host {upstream_hostport}
  }
}

What values are your using for those environment variables? It matters. Please completely fill out the help topic template. Don’t omit any details.

2 Likes

Thanks to @matt & @francislavoie. it working now!
Now it simpler with official Caddy docker image :slight_smile:

Here is my repo: GitHub - izulwahidin/Heroku-Reverse-Proxy: An simple way to create reverse proxy using heroku & caddy

1 Like