Caddy proxy to nuxt 3 app with proxied domain

75 views Asked by At

I am trying to get some docker containers setup so i can host a nuxt 3 app, that is served over HTTPS using caddy and cloudflare. I can get the nuxt app successfully built and running in a container on the default port:3000. I can also get caddy running in another container and accessible on port 8080 showing the default caddy landing page.

What i cannot get working is the cloudflare redirect to my local caddy container and then proxied to my nuxt app using my domain/cloudflare account.

I am using this repo for the cloudflare integration. I think there is something not working correctly in the Caddyfile but i dont know what it is. If i try to add tls:{} objects i get errors in the Caddy containers logs. What am i missing? Im new to docker so im sure its something easy i cant figure out..

Cloudflare has a domain and custom API token created

  • Zone > Zone > Read
  • Zone > DNS > Edit
  • I can ping my-domain.com and i get my local IP address returned, so looks like forwarding is working just fine.

docker-compose.yaml

version: "3.8"

name: nuxt-caddy
services:
  ui:
    container_name: ui
    build:
      context: .
      dockerfile: DockerFile
    ports:
      - "3000:3000"
    depends_on:
      - caddy
    restart: unless-stopped

  caddy:
    stdin_open: true
    tty: true
    container_name: caddy
    ports:
      - "8080:3000"
      - "443:3000"
    volumes:
      - caddy_data:/data
      - caddy_config:/config
      - ./Caddyfile:/etc/caddy/Caddyfile
    environment:
      - CF_API_TOKEN=my-secret-cloudflare-api-key
    image: iarekylew00t/caddy-cloudflare:latest
    restart: unless-stopped

volumes:
  caddy_data:
  caddy_config:

Dockerfile

# use node 18 alpine image
FROM node:18-alpine3.17

# create work directory in app folder
WORKDIR /app

# install required packages for node image
RUN apk --no-cache add openssh g++ make python3 git

# copy over package.json files
COPY package.json /app/
COPY package-lock.json /app/

# install all depencies
RUN npm ci && npm cache clean --force

# copy over all files to the work directory
ADD . /app

# build the project
RUN npm run build

# expose the host and port 3000 to the server
ENV HOST 0.0.0.0
EXPOSE 3000

# run the build project with node
ENTRYPOINT ["node", ".output/server/index.mjs"]

Caddyfile

{
  acme_dns cloudflare {env.CF_API_TOKEN}
}
  • I can access localhost:3000 and i get the nuxt app running from the docker just fine.
  • I can access localhost:8080 and i get the default caddy page from docker just fine.
  • Access to localhost:443 or https://localhost or https://my-domain.com doesnt work
0

There are 0 answers