Need help for run Nextjs App on caddy

1. The problem I’m having:

Hi Caddy,

I am trying to run nextjs app on caddy. and tried to dockerize my caddy and nextjs app and deploy to digitalocean. I was able to dockerize and the deploy but I am having getting Status Code:522 when I am hit the url.
not sure I have done the caddy server configuration correctly. So i need a guide to fix this.

2. Error messages and/or full log output:

caddy               | {"level":"error","ts":1704080541.9474113,"logger":"tls.obtain","msg":"will retry","error":"[www.treblesolutions.com] Obtain: [www.treblesolutions.com] solving challenges: authz https://acme.zerossl.com/v2/DV90/authz/xX3xmqztogUHETQ2YonUTw has unexpected status; order will fail: invalid (order=https://acme.zerossl.com/v2/DV90/order/JDSzlmiR4l1c-MH_nao5lQ) (ca=https://acme.zerossl.com/v2/DV90)","attempt":5,"retrying_in":600,"elapsed":785.456523285,"max_duration":2592000}
caddy               | {"level":"info","ts":1704081141.950609,"logger":"tls.obtain","msg":"obtaining certificate","identifier":"www.treblesolutions.com"}
caddy               | {"level":"info","ts":1704081143.463677,"logger":"tls.issuance.acme.acme_client","msg":"trying to solve challenge","identifier":"www.treblesolutions.com","challenge_type":"tls-alpn-01","ca":"https://acme-staging-v02.api.letsencrypt.org/directory"}
caddy               | {"level":"error","ts":1704081144.301682,"logger":"tls.issuance.acme.acme_client","msg":"challenge failed","identifier":"www.treblesolutions.com","challenge_type":"tls-alpn-01","problem":{"type":"urn:ietf:params:acme:error:unauthorized","title":"","detail":"Cannot negotiate ALPN protocol \"acme-tls/1\" for tls-alpn-01 challenge","instance":"","subproblems":[]}}
caddy               | {"level":"error","ts":1704081144.3035011,"logger":"tls.issuance.acme.acme_client","msg":"validating authorization","identifier":"www.treblesolutions.com","problem":{"type":"urn:ietf:params:acme:error:unauthorized","title":"","detail":"Cannot negotiate ALPN protocol \"acme-tls/1\" for tls-alpn-01 challenge","instance":"","subproblems":[]},"order":"https://acme-staging-v02.api.letsencrypt.org/acme/order/130762554/13351387634","attempt":1,"max_attempts":3}
caddy               | {"level":"info","ts":1704081145.9238741,"logger":"tls.issuance.acme.acme_client","msg":"trying to solve challenge","identifier":"www.treblesolutions.com","challenge_type":"http-01","ca":"https://acme-staging-v02.api.letsencrypt.org/directory"}
caddy               | {"level":"error","ts":1704081177.79243,"logger":"tls.issuance.acme.acme_client","msg":"challenge failed","identifier":"www.treblesolutions.com","challenge_type":"http-01","problem":{"type":"urn:ietf:params:acme:error:unauthorized","title":"","detail":"2606:4700:3035::6815:1fe3: Invalid response from http://www.treblesolutions.com/.well-known/acme-challenge/wRvBPPMrMjwJluucAhAxFAQVvhAicOn8RXkzz8J_bQ4: 522","instance":"","subproblems":[]}}
caddy               | {"level":"error","ts":1704081177.7935934,"logger":"tls.issuance.acme.acme_client","msg":"validating authorization","identifier":"www.treblesolutions.com","problem":{"type":"urn:ietf:params:acme:error:unauthorized","title":"","detail":"2606:4700:3035::6815:1fe3: Invalid response from http://www.treblesolutions.com/.well-known/acme-challenge/wRvBPPMrMjwJluucAhAxFAQVvhAicOn8RXkzz8J_bQ4: 522","instance":"","subproblems":[]},"order":"https://acme-staging-v02.api.letsencrypt.org/acme/order/130762554/13351388524","attempt":2,"max_attempts":3}
caddy               | {"level":"error","ts":1704081177.7936494,"logger":"tls.obtain","msg":"could not get certificate from issuer","identifier":"www.treblesolutions.com","issuer":"acme-v02.api.letsencrypt.org-directory","error":"HTTP 403 urn:ietf:params:acme:error:unauthorized - 2606:4700:3035::6815:1fe3: Invalid response from http://www.treblesolutions.com/.well-known/acme-challenge/wRvBPPMrMjwJluucAhAxFAQVvhAicOn8RXkzz8J_bQ4: 522"}
caddy               | {"level":"error","ts":1704081180.157338,"logger":"tls.obtain","msg":"could not get certificate from issuer","identifier":"www.treblesolutions.com","issuer":"acme.zerossl.com-v2-DV90","error":"[www.treblesolutions.com] solving challenges: authz https://acme.zerossl.com/v2/DV90/authz/xX3xmqztogUHETQ2YonUTw has unexpected status; order will fail: invalid (order=https://acme.zerossl.com/v2/DV90/order/JDSzlmiR4l1c-MH_nao5lQ) (ca=https://acme.zerossl.com/v2/DV90)"}
caddy               | {"level":"error","ts":1704081180.1574209,"logger":"tls.obtain","msg":"will retry","error":"[www.treblesolutions.com] Obtain: [www.treblesolutions.com] solving challenges: authz https://acme.zerossl.com/v2/DV90/authz/xX3xmqztogUHETQ2YonUTw has unexpected status; order will fail: invalid (order=https://acme.zerossl.com/v2/DV90/order/JDSzlmiR4l1c-MH_nao5lQ) (ca=https://acme.zerossl.com/v2/DV90)","attempt":6,"retrying_in":1200,"elapsed":1423.66653298,"max_duration":2592000}

3. Caddy version:

caddy:2.7.4

4. How I installed and ran Caddy:

I ran the caddy using docker container.

a. System environment:

OS: Linux
Docker

b. Command:

ENV=prod docker-compose -f docker-compose-prod.yml up

c. Service/unit/compose file:

Docker compose file

version: "3"
services:
  treble-solutions:
    container_name: treble-solutions
    image: treblesolutions/treble-solutions:${ENV}
    restart: unless-stopped
    build: 
      context: .
      args:
        BASE_URL: https://www.treblesolutions.com/
        NODE_ENV: production
        RESEND_API_KEY: RESEND_API_KEY
        EXCHANGE_API_KEY: EXCHANGE_API_KEY
        GOOGLE_ANALYTICS_KEY: GOOGLE_ANALYTICS_KEY
        NEXT_PUBLIC_RECAPTCHA_SITE_KEY: NEXT_PUBLIC_RECAPTCHA_SITE_KEY
        RECAPTCHA_SECRET_KEY: RECAPTCHA_SECRET_KEY
    env_file: ./${ENV}.env
    ports:
      - "7000:7000"
    networks:
      - caddy-network
    volumes:
      - caddy-data:/data
      - caddy-config:/config
      - /root/treble/uploads/treblesolutionsfrontenduploads/:/srv/treblesolutionsfrontenduploads
      - /var/caddy-logs:/var/log/caddy
  caddy:
    image: caddy:2.7.4
    restart: unless-stopped
    container_name: caddy
    ports:
      - "1080:80"
      - "1443:443"
    volumes:
      - $PWD/Caddyfile:/etc/caddy/Caddyfile
      - /var/caddy-data:/data
      - /var/caddy-config:/config
      - /var/caddy-logs:/var/log/caddy
networks:
  caddy-network:
    external: true
volumes:
  mongo-data:
    driver: local
  caddy-data:
    driver: local
  caddy-config:
    driver: local
  caddy-logs:
    driver: local

Dockerfile

FROM node:18-alpine AS base

# Install dependencies only when needed
FROM base AS deps
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
WORKDIR /app

# Install dependencies based on the preferred package manager
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
RUN \
  if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
  elif [ -f package-lock.json ]; then npm ci; \
  elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i --frozen-lockfile; \
  else echo "Lockfile not found." && exit 1; \
  fi


# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .

# Next.js collects completely anonymous telemetry data about general usage.
# Learn more here: https://nextjs.org/telemetry
# Uncomment the following line in case you want to disable telemetry during the build.
# ENV NEXT_TELEMETRY_DISABLED 1

ARG BASE_URL
ARG NODE_ENV
ARG RESEND_API_KEY
ARG EXCHANGE_API_KEY
ARG GOOGLE_ANALYTICS_KEY
ARG NEXT_PUBLIC_RECAPTCHA_SITE_KEY
ARG RECAPTCHA_SECRET_KEY

ENV REACT_APP_BASE_URL=${BASE_URL} \
    NODE_ENV=${NODE_ENV} \
    RESEND_API_KEY=${RESEND_API_KEY} \
    EXCHANGE_API_KEY=${EXCHANGE_API_KEY} \
    GOOGLE_ANALYTICS_KEY=${GOOGLE_ANALYTICS_KEY} \
    NEXT_PUBLIC_RECAPTCHA_SITE_KEY=${NEXT_PUBLIC_RECAPTCHA_SITE_KEY} \
    RECAPTCHA_SECRET_KEY=${RECAPTCHA_SECRET_KEY}

RUN yarn build

# If using npm comment out above and use below instead
# RUN npm run build

# Production image, copy all the files and run next
FROM base AS runner
WORKDIR /app

ENV NODE_ENV production
# Uncomment the following line in case you want to disable telemetry during runtime.
# ENV NEXT_TELEMETRY_DISABLED 1

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

COPY --from=builder /app/public ./public

# Set the correct permission for prerender cache
RUN mkdir .next
RUN chown nextjs:nodejs .next

# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static

USER nextjs

EXPOSE 7000

ENV PORT 7000
# set hostname to localhost
ENV HOSTNAME "0.0.0.0"

# server.js is created by next build from the standalone output
# https://nextjs.org/docs/pages/api-reference/next-config-js/output
CMD ["node", "server.js"]

d. My complete Caddy config:

(cors) {

    @cors_preflight{args.0} method OPTIONS
    @cors{args.0} header Origin {args.0}

    handle @cors_preflight{args.0} {
        header {
            Access-Control-Allow-Origin "{args.0}"
            Access-Control-Allow-Methods "GET, POST, PUT, PATCH, DELETE, OPTIONS"
            Access-Control-Allow-Headers *
            Access-Control-Max-Age "3600"
            defer
        }
        respond "" 204
    }

    handle @cors{args.0} {
        header {
            Access-Control-Allow-Origin "{args.0}"
            Access-Control-Expose-Headers *
            defer
        }
    }
}

www.treblesolutions.com:443 {

    log {
        level DEBUG
        output file /var/log/caddy/treble-solutions.log
        format json
    }

    tls treblesolution@gmail.com

    reverse_proxy treble-solutions:7000
}

5. Links to relevant resources:

That sounds like a Cloudflare issue.

If you have Cloudflare’s proxying enabled, then Caddy’s ACME issuance will fail to work by default.

You either need to turn off Cloudflare’s HTTP->HTTPS redirects (See Automatic HTTPS Rewrites · Cloudflare SSL/TLS docs) so that HTTP requests actually reach Caddy instead of being redirected, OR turn off Cloudflare proxying entirely so that requests reach your server directly.

Also, you’re exposing Caddy on different ports than the default. What are you doing with these ports? Are you port forwarding to different ports with your network router?

Keep in mind that Cloudflare only supports a few specific ports per protocol, and those you use aren’t supported Network ports · Cloudflare Fundamentals docs

Hi @francislavoie
Sorry for the late reply.

@francislavoie
Also, you’re exposing Caddy on different ports than the default. What are you doing with these ports? Are you port forwarding to different ports with your network router?

Actually In my digital ocean droplet I have main caddy server which is up and running in docker instance I used this main Caddy server to route my requests to other caddy servers inside the same droplet. so those caddy servers I did this port forwarding.

may be you can get understand my previous help question will attached like here.

Caddy Community Help previous question

Anyway I have changed my docker compose file without port forward here it is

version: "3"
services:
  treble-solutions:
    container_name: treble-solutions
    image: treblesolutions/treble-solutions:${ENV}
    restart: unless-stopped
    build:
      context: .
      args:
        BASE_URL=${{FRONTEND_BASE_URL_PROD }}
            NODE_ENV=${{NODE_ENV_PROD }}
            RESEND_API_KEY=${{RESEND_API_KEY }}
            EXCHANGE_API_KEY=${{EXCHANGE_API_KEY }}
            GOOGLE_ANALYTICS_KEY=${{GOOGLE_ANALYTICS_KEY }}
NEXT_PUBLIC_RECAPTCHA_SITE_KEY=${{NEXT_PUBLIC_RECAPTCHA_SITE_KEY }}
            RECAPTCHA_SECRET_KEY=${{RECAPTCHA_SECRET_KEY }}
    ports:
      - "7000:7000"
    networks:
      - caddy-network
    volumes:
      - caddy-data:/data
      - caddy-config:/config
      - /root/treble/uploads/treblesolutionsfrontenduploads/:/srv/treblesolutionsfrontenduploads
      - /var/caddy-logs:/var/log/caddy
networks:
  caddy-network:
    external: true
volumes:
  mongo-data:
    driver: local
  caddy-data:
    driver: local
  caddy-config:
    driver: local
  caddy-logs:
    driver: local

And dockerized nextjs app is running on port 7000

Now I am getting different error like this

And here is my caddy server log.

{"level":"error","ts":1705202353.8276112,"logger":"http.log.access.log0","msg":"handled request","request":{"remote_ip":"172.69.7.150","remote_port":"27126","client_ip":"172.69.7.150","proto":"HTTP/2.0","method":"GET","host":"www.treblesolutions.com","uri":"/opnegraph-image.jpeg","headers":{"Accept-Encoding":["gzip"],"X-Forwarded-For":["2a03:2880:10ff:c::face:b00c"],"Cf-Visitor":["{\"scheme\":\"https\"}"],"Accept":["*/*"],"User-Agent":["facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)"],"Cf-Ipcountry":["US"],"Cf-Ray":["8452bc722dfa6162-ORD"],"X-Forwarded-Proto":["https"],"Cf-Connecting-Ip":["2a03:2880:10ff:c::face:b00c"],"Cdn-Loop":["cloudflare"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"www.treblesolutions.com"}},"bytes_read":0,"user_id":"","duration":0.169980784,"size":3668,"status":404,"resp_headers":{"Content-Type":["text/html; charset=utf-8"],"Content-Encoding":["gzip"],"Cache-Control":["private, no-cache, no-store, max-age=0, must-revalidate"],"X-Powered-By":["Next.js"],"Server":["Caddy"],"Alt-Svc":["h3=\":443\"; ma=2592000"],"Date":["Sun, 14 Jan 2024 03:19:13 GMT"],"Vary":["RSC, Next-Router-State-Tree, Next-Router-Prefetch, Next-Url, Accept-Encoding"]}}

Any clue?

Did you try these things?

What do you mean by that? I don’t see Caddy in your Docker Compose config anymore.

This is just a single access log showing a 404. This means that Caddy did reach your app container but your app returned a 404.

But this doesn’t speak to the other issues. Please show all your logs, not just one cherrypicked entry. What we need to see if Caddy’s process logs, not your access logs. Enable the debug global option for more detailed logs.

1 Like

HI @francislavoie
Here is the full log

caddy    | {"level":"error","ts":1705697498.3678002,"logger":"http.log.error.log0","msg":"dial tcp 172.18.0.11:80: connect: connection refused","request":{"remote_ip":"162.158.163.154","remote_port":"60108","client_ip":"162.158.163.154","proto":"HTTP/2.0","method":"GET","host":"www.treblesolutions.com","uri":"/","headers":{"Accept-Encoding":["gzip"],"X-Forwarded-For":["2406:3003:2073:38a5:1124:4606:4097:e729"],"X-Forwarded-Proto":["https"],"User-Agent":["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"],"Sec-Purpose":["prefetch;prerender"],"Sec-Fetch-Mode":["navigate"],"Cf-Ipcountry":["SG"],"Cf-Visitor":["{\"scheme\":\"https\"}"],"Sec-Ch-Ua":["\"Not_A Brand\";v=\"8\", \"Chromium\";v=\"120\", \"Google Chrome\";v=\"120\""],"Sec-Ch-Ua-Mobile":["?0"],"Upgrade-Insecure-Requests":["1"],"Sec-Fetch-User":["?1"],"Sec-Fetch-Dest":["document"],"Cookie":[],"Cf-Connecting-Ip":["2406:3003:2073:38a5:1124:4606:4097:e729"],"Cdn-Loop":["cloudflare"],"Accept-Language":["en-US,en;q=0.9,ja;q=0.8"],"Cf-Ray":["8481f4f41c195fa5-SIN"],"Sec-Ch-Ua-Platform":["\"macOS\""],"Purpose":["prefetch"],"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7"],"Sec-Fetch-Site":["none"],"Priority":["u=0, i"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"www.treblesolutions.com"}},"duration":0.002315679,"status":502,"err_id":"rnvkvjk5q","err_trace":"reverseproxy.statusError (reverseproxy.go:1248)"}
caddy    | {"level":"error","ts":1705697501.6187055,"logger":"http.log.error.log0","msg":"dial tcp 172.18.0.11:80: connect: connection refused","request":{"remote_ip":"162.158.163.154","remote_port":"60108","client_ip":"162.158.163.154","proto":"HTTP/2.0","method":"GET","host":"www.treblesolutions.com","uri":"/","headers":{"Sec-Fetch-Mode":["navigate"],"Sec-Fetch-Dest":["document"],"X-Forwarded-For":["2406:3003:2073:38a5:1124:4606:4097:e729"],"Sec-Ch-Ua-Platform":["\"macOS\""],"Sec-Fetch-Site":["none"],"Cf-Ipcountry":["SG"],"Accept-Encoding":["gzip"],"Sec-Ch-Ua":["\"Not_A Brand\";v=\"8\", \"Chromium\";v=\"120\", \"Google Chrome\";v=\"120\""],"User-Agent":["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"],"Sec-Fetch-User":["?1"],"Accept-Language":["en-US,en;q=0.9,ja;q=0.8"],"Priority":["u=0, i"],"Cdn-Loop":["cloudflare"],"Cf-Ray":["8481f508ff4f5fa5-SIN"],"Sec-Ch-Ua-Mobile":["?0"],"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7"],"Cookie":[],"Cf-Connecting-Ip":["2406:3003:2073:38a5:1124:4606:4097:e729"],"X-Forwarded-Proto":["https"],"Cf-Visitor":["{\"scheme\":\"https\"}"],"Upgrade-Insecure-Requests":["1"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"www.treblesolutions.com"}},"duration":0.000698571,"status":502,"err_id":"41n1yb8is","err_trace":"reverseproxy.statusError (reverseproxy.go:1248)"}
caddy    | {"level":"error","ts":1705697501.878793,"logger":"http.log.error.log0","msg":"dial tcp 172.18.0.11:80: connect: connection refused","request":{"remote_ip":"162.158.162.85","remote_port":"20272","client_ip":"162.158.162.85","proto":"HTTP/2.0","method":"GET","host":"www.treblesolutions.com","uri":"/favicon.ico","headers":{"Accept-Encoding":["gzip"],"Sec-Ch-Ua":["\"Not_A Brand\";v=\"8\", \"Chromium\";v=\"120\", \"Google Chrome\";v=\"120\""],"User-Agent":["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"],"Sec-Ch-Ua-Platform":["\"macOS\""],"Sec-Fetch-Site":["same-origin"],"Referer":["https://www.treblesolutions.com/"],"Cookie":[],"X-Forwarded-For":["2406:3003:2073:38a5:1124:4606:4097:e729"],"Accept":["image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8"],"Priority":["u=1, i"],"Cf-Ray":["8481f50a1ffe5fa5-SIN"],"Cf-Visitor":["{\"scheme\":\"https\"}"],"Sec-Ch-Ua-Mobile":["?0"],"Sec-Fetch-Mode":["no-cors"],"Accept-Language":["en-US,en;q=0.9,ja;q=0.8"],"Cdn-Loop":["cloudflare"],"Cf-Ipcountry":["SG"],"X-Forwarded-Proto":["https"],"Sec-Fetch-Dest":["image"],"Cf-Connecting-Ip":["2406:3003:2073:38a5:1124:4606:4097:e729"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"www.treblesolutions.com"}},"duration":0.000953606,"status":502,"err_id":"smftzca3i","err_trace":"reverseproxy.statusError (reverseproxy.go:1248)"}

Hi @francislavoie

Here is the full log

{"level":"error","ts":1705697788.1990476,"logger":"http.log.access.log0","msg":"handled request","request":{"remote_ip":"162.158.190.77","remote_port":"41722","client_ip":"162.158.190.77","proto":"HTTP/2.0","method":"GET","host":"www.treblesolutions.com","uri":"/","headers":{"Priority":["u=0, i"],"X-Forwarded-Proto":["https"],"Cf-Visitor":["{\"scheme\":\"https\"}"],"Sec-Ch-Ua-Mobile":["?0"],"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7"],"Accept-Language":["en-US,en;q=0.9,ja;q=0.8"],"Sec-Fetch-Site":["none"],"Sec-Fetch-User":["?1"],"Sec-Fetch-Dest":["document"],"Cdn-Loop":["cloudflare"],"Cf-Ray":["8481fc078e1f401e-SIN"],"Cache-Control":["max-age=0"],"Sec-Ch-Ua-Platform":["\"macOS\""],"User-Agent":["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"],"Cookie":[],"Cf-Connecting-Ip":["2406:3003:2073:38a5:1124:4606:4097:e729"],"Cf-Ipcountry":["SG"],"Accept-Encoding":["gzip"],"X-Forwarded-For":["2406:3003:2073:38a5:1124:4606:4097:e729"],"Sec-Ch-Ua":["\"Not_A Brand\";v=\"8\", \"Chromium\";v=\"120\", \"Google Chrome\";v=\"120\""],"Upgrade-Insecure-Requests":["1"],"Sec-Fetch-Mode":["navigate"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"www.treblesolutions.com"}},"bytes_read":0,"user_id":"","duration":0.001314933,"size":0,"status":502,"resp_headers":{"Server":["Caddy"],"Alt-Svc":["h3=\":443\"; ma=2592000"]}}
{"level":"error","ts":1705697788.399279,"logger":"http.log.access.log0","msg":"handled request","request":{"remote_ip":"162.158.189.141","remote_port":"46078","client_ip":"162.158.189.141","proto":"HTTP/2.0","method":"GET","host":"www.treblesolutions.com","uri":"/favicon.ico","headers":{"Cf-Connecting-Ip":["2406:3003:2073:38a5:1124:4606:4097:e729"],"Cf-Ipcountry":["SG"],"Cf-Visitor":["{\"scheme\":\"https\"}"],"Sec-Ch-Ua-Mobile":["?0"],"Referer":["https://www.treblesolutions.com/"],"Cookie":[],"Cdn-Loop":["cloudflare"],"X-Forwarded-Proto":["https"],"Sec-Fetch-Mode":["no-cors"],"Accept-Language":["en-US,en;q=0.9,ja;q=0.8"],"Priority":["u=1, i"],"Accept-Encoding":["gzip"],"Sec-Ch-Ua-Platform":["\"macOS\""],"Accept":["image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8"],"Sec-Fetch-Dest":["image"],"X-Forwarded-For":["2406:3003:2073:38a5:1124:4606:4097:e729"],"Cf-Ray":["8481fc08ded3401e-SIN"],"Sec-Ch-Ua":["\"Not_A Brand\";v=\"8\", \"Chromium\";v=\"120\", \"Google Chrome\";v=\"120\""],"User-Agent":["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"],"Sec-Fetch-Site":["same-origin"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"www.treblesolutions.com"}},"bytes_read":0,"user_id":"","duration":0.000722004,"size":0,"status":502,"resp_headers":{"Server":["Caddy"],"Alt-Svc":["h3=\":443\"; ma=2592000"]}}

This means Caddy was trying to connect to your upstream on port 80 and the connection was refused.

Are you sure you configured reverse_proxy with the correct port?

1 Like

Hi @francislavoie

Yes you are correct. I was pointing to incorrect docker instance. anyway even I put the correct docker instance now I am getting different error : server misbehaving

here is that.

caddy    | {"level":"error","ts":1705711657.1500354,"logger":"http.log.error.log0","msg":"dial tcp: lookup caddy-treble-solutions on 127.0.0.11:53: server misbehaving","request":{"remote_ip":"172.70.189.156","remote_port":"54474","client_ip":"172.70.189.156","proto":"HTTP/2.0","method":"GET","host":"www.treblesolutions.com","uri":"/","headers":{"Sec-Fetch-User":["?1"],"Accept-Language":["en-US,en;q=0.9,ja;q=0.8"],"Cf-Connecting-Ip":["2406:3003:2073:38a5:1124:4606:4097:e729"],"Cdn-Loop":["cloudflare"],"Cf-Ipcountry":["SG"],"Upgrade-Insecure-Requests":["1"],"User-Agent":["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"],"Priority":["u=0, i"],"Accept-Encoding":["gzip"],"X-Forwarded-For":["2406:3003:2073:38a5:1124:4606:4097:e729"],"Cf-Visitor":["{\"scheme\":\"https\"}"],"Cookie":[],"Sec-Fetch-Site":["none"],"Sec-Fetch-Dest":["document"],"X-Forwarded-Proto":["https"],"Sec-Ch-Ua":["\"Not_A Brand\";v=\"8\", \"Chromium\";v=\"120\", \"Google Chrome\";v=\"120\""],"Sec-Ch-Ua-Mobile":["?0"],"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7"],"Sec-Fetch-Mode":["navigate"],"Cf-Ray":["84834ea0883787dd-SIN"],"Pragma":["no-cache"],"Cache-Control":["no-cache"],"Sec-Ch-Ua-Platform":["\"macOS\""]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"www.treblesolutions.com"}},"duration":0.001413857,"status":502,"err_id":"k95q8jmpp","err_trace":"reverseproxy.statusError (reverseproxy.go:1248)"}
caddy    | {"level":"error","ts":1705711657.365051,"logger":"http.log.error.log0","msg":"dial tcp: lookup caddy-treble-solutions on 127.0.0.11:53: server misbehaving","request":{"remote_ip":"172.70.189.79","remote_port":"42800","client_ip":"172.70.189.79","proto":"HTTP/2.0","method":"GET","host":"www.treblesolutions.com","uri":"/favicon.ico","headers":{"X-Forwarded-Proto":["https"],"Sec-Ch-Ua":["\"Not_A Brand\";v=\"8\", \"Chromium\";v=\"120\", \"Google Chrome\";v=\"120\""],"Sec-Fetch-Site":["same-origin"],"Sec-Fetch-Dest":["image"],"Accept-Language":["en-US,en;q=0.9,ja;q=0.8"],"Cdn-Loop":["cloudflare"],"Accept-Encoding":["gzip"],"Accept":["image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8"],"Sec-Fetch-Mode":["no-cors"],"Referer":["https://www.treblesolutions.com/"],"Cookie":[],"Cf-Ipcountry":["SG"],"Cf-Ray":["84834ea1d94f87dd-SIN"],"Sec-Ch-Ua-Mobile":["?0"],"Sec-Ch-Ua-Platform":["\"macOS\""],"Cf-Connecting-Ip":["2406:3003:2073:38a5:1124:4606:4097:e729"],"X-Forwarded-For":["2406:3003:2073:38a5:1124:4606:4097:e729"],"Cache-Control":["no-cache"],"User-Agent":["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"],"Priority":["u=1, i"],"Cf-Visitor":["{\"scheme\":\"https\"}"],"Pragma":["no-cache"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"www.treblesolutions.com"}},"duration":0.001596575,"status":502,"err_id":"is9khjhae","err_trace":"reverseproxy.statusError (reverseproxy.go:1248)"}
caddy    | {"level":"error","ts":1705711659.8413014,"logger":"http.log.error.log0","msg":"dial tcp: lookup caddy-treble-solutions on 127.0.0.11:53: server misbehaving","request":{"remote_ip":"172.70.189.156","remote_port":"54474","client_ip":"172.70.189.156","proto":"HTTP/2.0","method":"GET","host":"www.treblesolutions.com","uri":"/","headers":{"Sec-Fetch-Dest":["document"],"Cookie":[],"Sec-Ch-Ua":["\"Not_A Brand\";v=\"8\", \"Chromium\";v=\"120\", \"Google Chrome\";v=\"120\""],"User-Agent":["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"],"Sec-Fetch-User":["?1"],"Pragma":["no-cache"],"Sec-Ch-Ua-Mobile":["?0"],"Upgrade-Insecure-Requests":["1"],"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7"],"Cdn-Loop":["cloudflare"],"Accept-Encoding":["gzip"],"X-Forwarded-Proto":["https"],"Sec-Ch-Ua-Platform":["\"macOS\""],"Sec-Fetch-Site":["none"],"Cf-Ipcountry":["SG"],"X-Forwarded-For":["2406:3003:2073:38a5:1124:4606:4097:e729"],"Cf-Visitor":["{\"scheme\":\"https\"}"],"Accept-Language":["en-US,en;q=0.9,ja;q=0.8"],"Priority":["u=0, i"],"Cf-Connecting-Ip":["2406:3003:2073:38a5:1124:4606:4097:e729"],"Cf-Ray":["84834eb1dcf387dd-SIN"],"Cache-Control":["no-cache"],"Sec-Fetch-Mode":["navigate"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"www.treblesolutions.com"}},"duration":0.001199758,"status":502,"err_id":"3wz1tmem0","err_trace":"reverseproxy.statusError (reverseproxy.go:1248)"}

This is how my main caddyfile configured : ( my main caddy server also docker instance )

(cors) {

    @cors_preflight{args.0} method OPTIONS
    @cors{args.0} header Origin {args.0}

    handle @cors_preflight{args.0} {
        header {
            Access-Control-Allow-Origin "{args.0}"
            Access-Control-Allow-Methods "GET, POST, PUT, PATCH, DELETE, OPTIONS"
            Access-Control-Allow-Headers *
            Access-Control-Max-Age "3600"
            defer
        }
        respond "" 204
    }

    handle @cors{args.0} {
        header {
            Access-Control-Allow-Origin "{args.0}"
            Access-Control-Expose-Headers *
            defer
        }
    }
}

www.treblesolutions.com:443 {

    log {
        level DEBUG
        output file /var/log/caddy/treble-solutions-main.log
        format json
    }

    tls treblesolution@gmail.com

    reverse_proxy caddy-treble-solutions:80
}

And this is my nextjs app running caddyfile configurations : ( Here reverse proxy I am pointing to my nextjs app instance)

(cors) {

    @cors_preflight{args.0} method OPTIONS
    @cors{args.0} header Origin {args.0}

    handle @cors_preflight{args.0} {
        header {
            Access-Control-Allow-Origin "{args.0}"
            Access-Control-Allow-Methods "GET, POST, PUT, PATCH, DELETE, OPTIONS"
            Access-Control-Allow-Headers *
            Access-Control-Max-Age "3600"
            defer
        }
        respond "" 204
    }

    handle @cors{args.0} {
        header {
            Access-Control-Allow-Origin "{args.0}"
            Access-Control-Expose-Headers *
            defer
        }
    }
}

:80 {

    log {
        level DEBUG
        output file /var/log/caddy/treble-solutions.log
        format json
    }

    tls treblesolution@gmail.com

    reverse_proxy treble-solutions:7000
}

And here is my updated docker compose yml file :


version: "3"
services:
  treble-solutions:
    container_name: treble-solutions
    image: treblesolutions/treble-solutions:${ENV}
    restart: unless-stopped
    env_file: ./${ENV}.env
    ports:
      - "7000:7000"
    networks:
      - caddy-network
    volumes:
      - caddy-data:/data
      - caddy-config:/config
      - /root/treble/uploads/treblesolutionsfrontenduploads/:/srv/treblesolutionsfrontenduploads
      - /var/caddy-logs:/var/log/caddy
  caddy-treble-solutions:
    container_name: caddy-treble-solutions
    image: caddy:2.7.4
    restart: unless-stopped
    ports:
      - "1080:80"
      - "1443:443"
    volumes:
      - $PWD/Caddyfile.prod:/etc/caddy/Caddyfile
      - /var/caddy-data:/data
      - /var/caddy-config:/config
      - /var/caddy-logs:/var/log/caddy
networks:
  caddy-network:
    external: true
volumes:
  mongo-data:
    driver: local
  caddy-data:
    driver: local
  caddy-config:
    driver: local
  caddy-logs:
    driver: local

And here you can find how my instance are running ( ports )

nextjs app I have dockerize like this

FROM node:18-alpine AS base

# Install dependencies only when needed
FROM base AS deps
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
WORKDIR /app

# Install dependencies based on the preferred package manager
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./

RUN \
  if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
  elif [ -f package-lock.json ]; then npm ci; \
  elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i --frozen-lockfile; \
  else echo "Lockfile not found." && exit 1; \
  fi


# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .

# Next.js collects completely anonymous telemetry data about general usage.
# Learn more here: https://nextjs.org/telemetry
# Uncomment the following line in case you want to disable telemetry during the build.
# ENV NEXT_TELEMETRY_DISABLED 1

ARG BASE_URL
ARG NODE_ENV
ARG RESEND_API_KEY
ARG EXCHANGE_API_KEY
ARG GOOGLE_ANALYTICS_KEY
ARG NEXT_PUBLIC_RECAPTCHA_SITE_KEY
ARG RECAPTCHA_SECRET_KEY

ENV REACT_APP_BASE_URL=${BASE_URL} \
    NODE_ENV=${NODE_ENV} \
    RESEND_API_KEY=${RESEND_API_KEY} \
    EXCHANGE_API_KEY=${EXCHANGE_API_KEY} \
    GOOGLE_ANALYTICS_KEY=${GOOGLE_ANALYTICS_KEY} \
    NEXT_PUBLIC_RECAPTCHA_SITE_KEY=${NEXT_PUBLIC_RECAPTCHA_SITE_KEY} \
    RECAPTCHA_SECRET_KEY=${RECAPTCHA_SECRET_KEY}

RUN yarn build

# If using npm comment out above and use below instead
# RUN npm run build

# Production image, copy all the files and run next
FROM base AS runner
WORKDIR /app

ENV NODE_ENV production
# Uncomment the following line in case you want to disable telemetry during runtime.
# ENV NEXT_TELEMETRY_DISABLED 1

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

COPY --from=builder /app/public ./public

# Set the correct permission for prerender cache
RUN mkdir .next
RUN chown nextjs:nodejs .next

# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
COPY --from=builder --chown=nextjs:nodejs /app/public ./public
COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next
COPY --from=builder --chown=nextjs:nodejs /app/node_modules ./node_modules
COPY --from=builder --chown=nextjs:nodejs /app/package.json ./package.json

USER nextjs

EXPOSE 7000

ENV PORT 7000
# set hostname to localhost
ENV HOSTNAME "0.0.0.0"

# server.js is created by next build from the standalone output
# https://nextjs.org/docs/pages/api-reference/next-config-js/output
CMD ["node", "server.js"]

@francislavoie
Please help me to verify my configurations are correct and I really needs configure this on caddy.

That’s because Docker can’t resolve that name.

I think you forgot to add networks to that container, so it’s not in the same network as your other Caddy instance.

1 Like

@francislavoie

Yeah! I think now everything is working fine. I changed the dns to caddy server and now everything woking fine.

Thank you so much @francislavoie for you quick response.

Main Caddy logs :

{"level":"info","ts":1705716190.8649092,"logger":"http.log.access.log0","msg":"handled request","request":{"remote_ip":"172.69.166.62","remote_port":"61900","client_ip":"172.69.166.62","proto":"HTTP/2.0","method":"GET","host":"www.treblesolutions.com","uri":"/en","headers":{"X-Forwarded-For":["2406:3003:2073:38a5:1124:4606:4097:e729"],"Cf-Ray":["8483bd501aba495f-SIN"],"Sec-Ch-Ua-Mobile":["?0"],"Sec-Fetch-Mode":["navigate"],"Priority":["u=0, i"],"Accept-Encoding":["gzip"],"Cf-Visitor":["{\"scheme\":\"https\"}"],"Upgrade-Insecure-Requests":["1"],"Cookie":[],"Cdn-Loop":["cloudflare"],"Cf-Ipcountry":["SG"],"Sec-Ch-Ua-Platform":["\"macOS\""],"User-Agent":["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"],"Sec-Fetch-Dest":["document"],"Accept-Language":["en-US,en;q=0.9,ja;q=0.8"],"If-None-Match":["W/\"us3a73pcnej1k\""],"X-Forwarded-Proto":["https"],"Cache-Control":["max-age=0"],"Sec-Ch-Ua":["\"Not_A Brand\";v=\"8\", \"Chromium\";v=\"120\", \"Google Chrome\";v=\"120\""],"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7"],"Sec-Fetch-Site":["none"],"Sec-Fetch-User":["?1"],"Cf-Connecting-Ip":["2406:3003:2073:38a5:1124:4606:4097:e729"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"www.treblesolutions.com"}},"bytes_read":0,"user_id":"","duration":0.010142875,"size":15756,"status":200,"resp_headers":{"Alt-Svc":["h3=\":443\"; ma=2592000"],"Cache-Control":["s-maxage=31536000, stale-while-revalidate"],"X-Powered-By":["Next.js"],"Content-Encoding":["gzip"],"Content-Type":["text/html; charset=utf-8"],"Date":["Sat, 20 Jan 2024 02:03:10 GMT"],"Server":["Caddy","Caddy"],"Etag":["\"bczexu8oz926ap\""],"X-Nextjs-Cache":["HIT"],"Vary":["RSC, Next-Router-State-Tree, Next-Router-Prefetch, Next-Url, Accept-Encoding"]}}
{"level":"info","ts":1705716191.0175204,"logger":"http.log.access.log0","msg":"handled request","request":{"remote_ip":"172.69.166.62","remote_port":"61900","client_ip":"172.69.166.62","proto":"HTTP/2.0","method":"GET","host":"www.treblesolutions.com","uri":"/_next/image?url=%2Fassets%2Fmain-logo.png&w=384&q=75","headers":{"Accept-Language":["en-US,en;q=0.9,ja;q=0.8"],"Cdn-Loop":["cloudflare"],"X-Forwarded-For":["2406:3003:2073:38a5:1124:4606:4097:e729"],"X-Forwarded-Proto":["https"],"Accept":["image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8"],"Referer":["https://www.treblesolutions.com/en"],"Sec-Ch-Ua":["\"Not_A Brand\";v=\"8\", \"Chromium\";v=\"120\", \"Google Chrome\";v=\"120\""],"Sec-Fetch-Site":["same-origin"],"Priority":["u=3, i"],"Cookie":[],"Cf-Connecting-Ip":["2406:3003:2073:38a5:1124:4606:4097:e729"],"Cf-Ipcountry":["SG"],"Cf-Visitor":["{\"scheme\":\"https\"}"],"User-Agent":["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"],"Sec-Ch-Ua-Platform":["\"macOS\""],"Sec-Fetch-Mode":["no-cors"],"Accept-Encoding":["gzip"],"Cf-Ray":["8483bd51abf1495f-SIN"],"If-None-Match":["wAFeNmUP3wKPuE2AIFkQ+VNq9y67yy5adScnSnOdbGk="],"Sec-Ch-Ua-Mobile":["?0"],"Sec-Fetch-Dest":["image"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"www.treblesolutions.com"}},"bytes_read":0,"user_id":"","duration":0.004332118,"size":0,"status":304,"resp_headers":{"Alt-Svc":["h3=\":443\"; ma=2592000"],"Cache-Control":["public, max-age=60, must-revalidate"],"Date":["Sat, 20 Jan 2024 02:03:11 GMT"],"Etag":["wAFeNmUP3wKPuE2AIFkQ+VNq9y67yy5adScnSnOdbGk="],"Vary":["Accept"],"Server":["Caddy","Caddy"]}}
{"level":"info","ts":1705716191.1059544,"logger":"http.log.access.log0","msg":"handled request","request":{"remote_ip":"172.69.166.62","remote_port":"61900","client_ip":"172.69.166.62","proto":"HTTP/2.0","method":"GET","host":"www.treblesolutions.com","uri":"/api/get-rates","headers":{"X-Forwarded-Proto":["https"],"Sec-Ch-Ua-Mobile":["?0"],"Sec-Ch-Ua-Platform":["\"macOS\""],"Cf-Visitor":["{\"scheme\":\"https\"}"],"User-Agent":["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"],"Accept":["*/*"],"Sec-Fetch-Mode":["cors"],"Cookie":[],"Cf-Connecting-Ip":["2406:3003:2073:38a5:1124:4606:4097:e729"],"Cdn-Loop":["cloudflare"],"Accept-Encoding":["gzip"],"Sec-Ch-Ua":["\"Not_A Brand\";v=\"8\", \"Chromium\";v=\"120\", \"Google Chrome\";v=\"120\""],"Sec-Fetch-Site":["same-origin"],"Sec-Fetch-Dest":["empty"],"Accept-Language":["en-US,en;q=0.9,ja;q=0.8"],"Cf-Ipcountry":["SG"],"X-Forwarded-For":["2406:3003:2073:38a5:1124:4606:4097:e729"],"Cf-Ray":["8483bd523c43495f-SIN"],"Referer":["https://www.treblesolutions.com/en"],"Priority":["u=1, i"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"www.treblesolutions.com"}},"bytes_read":0,"user_id":"","duration":0.005026186,"size":381,"status":200,"resp_headers":{"Vary":["RSC, Next-Router-State-Tree, Next-Router-Prefetch, Next-Url"],"X-Nextjs-Cache":["HIT"],"Server":["Caddy","Caddy"],"Alt-Svc":["h3=\":443\"; ma=2592000"],"Content-Type":["application/json"],"Date":["Sat, 20 Jan 2024 02:03:11 GMT"]}}
{"level":"info","ts":1705716191.2112286,"logger":"http.log.access.log0","msg":"handled request","request":{"remote_ip":"172.69.166.63","remote_port":"9490","client_ip":"172.69.166.63","proto":"HTTP/2.0","method":"GET","host":"www.treblesolutions.com","uri":"/en?_rsc=16ipr","headers":{"Cookie":[],"Cdn-Loop":["cloudflare"],"Sec-Ch-Ua":["\"Not_A Brand\";v=\"8\", \"Chromium\";v=\"120\", \"Google Chrome\";v=\"120\""],"Sec-Fetch-Mode":["cors"],"Referer":["https://www.treblesolutions.com/en"],"Sec-Fetch-Site":["same-origin"],"If-None-Match":["W/\"us3a73pcnej1k\""],"Priority":["u=1, i"],"Cf-Ipcountry":["SG"],"X-Forwarded-For":["2406:3003:2073:38a5:1124:4606:4097:e729"],"Cf-Ray":["8483bd525c5a495f-SIN"],"Next-Url":["/en"],"Sec-Ch-Ua-Mobile":["?0"],"Next-Router-State-Tree":["%5B%22%22%2C%7B%22children%22%3A%5B%22en%22%2C%7B%22children%22%3A%5B%22__PAGE__%22%2C%7B%7D%5D%7D%5D%7D%2Cnull%2Cnull%2Ctrue%5D"],"Accept-Language":["en-US,en;q=0.9,ja;q=0.8"],"Cf-Connecting-Ip":["2406:3003:2073:38a5:1124:4606:4097:e729"],"Accept-Encoding":["gzip"],"User-Agent":["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"],"Sec-Ch-Ua-Platform":["\"macOS\""],"Accept":["*/*"],"X-Forwarded-Proto":["https"],"Cf-Visitor":["{\"scheme\":\"https\"}"],"Next-Router-Prefetch":["1"],"Rsc":["1"],"Sec-Fetch-Dest":["empty"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"www.treblesolutions.com"}},"bytes_read":0,"user_id":"","duration":0.009596637,"size":0,"status":304,"resp_headers":{"Server":["Caddy","Caddy"],"Alt-Svc":["h3=\":443\"; ma=2592000"],"Vary":["RSC, Next-Router-State-Tree, Next-Router-Prefetch, Next-Url"],"X-Nextjs-Cache":["HIT"],"Cache-Control":["s-maxage=31536000, stale-while-revalidate"],"Date":["Sat, 20 Jan 2024 02:03:11 GMT"],"Etag":["\"us3a73pcnej1k\""]}}
{"level":"info","ts":1705716191.7774477,"logger":"http.log.access.log0","msg":"handled request","request":{"remote_ip":"172.69.166.63","remote_port":"9484","client_ip":"172.69.166.63","proto":"HTTP/2.0","method":"GET","host":"www.treblesolutions.com","uri":"/?_rsc=16ipr","headers":{"Accept-Encoding":["gzip"],"Sec-Fetch-Mode":["cors"],"Next-Router-Prefetch":["1"],"Next-Url":["/en"],"Accept":["*/*"],"Sec-Fetch-Dest":["empty"],"Cf-Ipcountry":["SG"],"Cf-Ray":["8483bd525c57495f-SIN"],"X-Forwarded-Proto":["https"],"Next-Router-State-Tree":["%5B%22%22%2C%7B%22children%22%3A%5B%22en%22%2C%7B%22children%22%3A%5B%22__PAGE__%22%2C%7B%7D%5D%7D%5D%7D%2Cnull%2Cnull%2Ctrue%5D"],"Accept-Language":["en-US,en;q=0.9,ja;q=0.8"],"Cf-Connecting-Ip":["2406:3003:2073:38a5:1124:4606:4097:e729"],"Sec-Fetch-Site":["same-origin"],"Referer":["https://www.treblesolutions.com/en"],"Cookie":[],"Priority":["u=1, i"],"Cdn-Loop":["cloudflare"],"X-Forwarded-For":["2406:3003:2073:38a5:1124:4606:4097:e729"],"Cf-Visitor":["{\"scheme\":\"https\"}"],"Sec-Ch-Ua":["\"Not_A Brand\";v=\"8\", \"Chromium\";v=\"120\", \"Google Chrome\";v=\"120\""],"Sec-Ch-Ua-Mobile":["?0"],"User-Agent":["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"],"Rsc":["1"],"Sec-Ch-Ua-Platform":["\"macOS\""]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"www.treblesolutions.com"}},"bytes_read":0,"user_id":"","duration":0.578388735,"size":3,"status":307,"resp_headers":{"Alt-Svc":["h3=\":443\"; ma=2592000"],"Date":["Sat, 20 Jan 2024 02:03:11 GMT"],"Location":["/en"],"Server":["Caddy","Caddy"]}}
{"level":"info","ts":1705716191.8411024,"logger":"http.log.access.log0","msg":"handled request","request":{"remote_ip":"172.69.166.62","remote_port":"61900","client_ip":"172.69.166.62","proto":"HTTP/2.0","method":"GET","host":"www.treblesolutions.com","uri":"/en","headers":{"Next-Url":["/en"],"Accept":["*/*"],"Referer":["https://www.treblesolutions.com/en"],"Cdn-Loop":["cloudflare"],"Accept-Encoding":["gzip"],"Sec-Ch-Ua-Mobile":["?0"],"Sec-Ch-Ua-Platform":["\"macOS\""],"Cookie":[],"Cf-Connecting-Ip":["2406:3003:2073:38a5:1124:4606:4097:e729"],"X-Forwarded-For":["2406:3003:2073:38a5:1124:4606:4097:e729"],"Cf-Ray":["8483bd56d892495f-SIN"],"Sec-Ch-Ua":["\"Not_A Brand\";v=\"8\", \"Chromium\";v=\"120\", \"Google Chrome\";v=\"120\""],"Next-Router-State-Tree":["%5B%22%22%2C%7B%22children%22%3A%5B%22en%22%2C%7B%22children%22%3A%5B%22__PAGE__%22%2C%7B%7D%5D%7D%5D%7D%2Cnull%2Cnull%2Ctrue%5D"],"Next-Router-Prefetch":["1"],"User-Agent":["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"],"Sec-Fetch-Dest":["empty"],"Accept-Language":["en-US,en;q=0.9,ja;q=0.8"],"X-Forwarded-Proto":["https"],"Cf-Visitor":["{\"scheme\":\"https\"}"],"Priority":["u=1, i"],"Sec-Fetch-Site":["same-origin"],"Sec-Fetch-Mode":["cors"],"Cf-Ipcountry":["SG"],"Rsc":["1"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"www.treblesolutions.com"}},"bytes_read":0,"user_id":"","duration":0.003820607,"size":6118,"status":200,"resp_headers":{"Alt-Svc":["h3=\":443\"; ma=2592000"],"Content-Encoding":["gzip"],"Vary":["RSC, Next-Router-State-Tree, Next-Router-Prefetch, Next-Url, Accept-Encoding"],"Cache-Control":["s-maxage=31536000, stale-while-revalidate"],"Etag":["\"us3a73pcnej1k\""],"X-Nextjs-Cache":["HIT"],"Server":["Caddy","Caddy"],"Date":["Sat, 20 Jan 2024 02:03:11 GMT"],"Content-Type":["text/x-component"]}}

nextjs app caddy logs:

{"level":"info","ts":1705716190.8644376,"logger":"http.log.access.log0","msg":"handled request","request":{"remote_ip":"172.18.0.2","remote_port":"47256","client_ip":"172.18.0.2","proto":"HTTP/1.1","method":"GET","host":"www.treblesolutions.com","uri":"/en","headers":{"User-Agent":["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"],"Cf-Ipcountry":["SG"],"Sec-Fetch-Mode":["navigate"],"Upgrade-Insecure-Requests":["1"],"X-Forwarded-Proto":["https"],"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7"],"Priority":["u=0, i"],"Accept-Encoding":["gzip"],"Cdn-Loop":["cloudflare"],"Cache-Control":["max-age=0"],"Cf-Connecting-Ip":["2406:3003:2073:38a5:1124:4606:4097:e729"],"Cf-Ray":["8483bd501aba495f-SIN"],"Sec-Ch-Ua":["\"Not_A Brand\";v=\"8\", \"Chromium\";v=\"120\", \"Google Chrome\";v=\"120\""],"Sec-Fetch-User":["?1"],"Accept-Language":["en-US,en;q=0.9,ja;q=0.8"],"Sec-Ch-Ua-Mobile":["?0"],"Sec-Ch-Ua-Platform":["\"macOS\""],"Cf-Visitor":["{\"scheme\":\"https\"}"],"Cookie":[],"X-Forwarded-For":["172.69.166.62"],"If-None-Match":["W/\"us3a73pcnej1k\""],"Sec-Fetch-Dest":["document"],"Sec-Fetch-Site":["none"],"X-Forwarded-Host":["www.treblesolutions.com"]}},"bytes_read":0,"user_id":"","duration":0.008204604,"size":15756,"status":200,"resp_headers":{"Server":["Caddy"],"Date":["Sat, 20 Jan 2024 02:03:10 GMT"],"Content-Type":["text/html; charset=utf-8"],"X-Nextjs-Cache":["HIT"],"X-Powered-By":["Next.js"],"Vary":["RSC, Next-Router-State-Tree, Next-Router-Prefetch, Next-Url, Accept-Encoding"],"Etag":["\"bczexu8oz926ap\""],"Content-Encoding":["gzip"],"Cache-Control":["s-maxage=31536000, stale-while-revalidate"]}}
{"level":"info","ts":1705716191.0170934,"logger":"http.log.access.log0","msg":"handled request","request":{"remote_ip":"172.18.0.2","remote_port":"47256","client_ip":"172.18.0.2","proto":"HTTP/1.1","method":"GET","host":"www.treblesolutions.com","uri":"/_next/image?url=%2Fassets%2Fmain-logo.png&w=384&q=75","headers":{"Sec-Ch-Ua-Platform":["\"macOS\""],"Sec-Fetch-Dest":["image"],"Accept":["image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8"],"Accept-Encoding":["gzip"],"Cdn-Loop":["cloudflare"],"Cf-Ipcountry":["SG"],"Sec-Ch-Ua-Mobile":["?0"],"X-Forwarded-Host":["www.treblesolutions.com"],"Cf-Ray":["8483bd51abf1495f-SIN"],"Cf-Visitor":["{\"scheme\":\"https\"}"],"Cookie":[],"Referer":["https://www.treblesolutions.com/en"],"Sec-Ch-Ua":["\"Not_A Brand\";v=\"8\", \"Chromium\";v=\"120\", \"Google Chrome\";v=\"120\""],"X-Forwarded-Proto":["https"],"Accept-Language":["en-US,en;q=0.9,ja;q=0.8"],"Cf-Connecting-Ip":["2406:3003:2073:38a5:1124:4606:4097:e729"],"If-None-Match":["wAFeNmUP3wKPuE2AIFkQ+VNq9y67yy5adScnSnOdbGk="],"Priority":["u=3, i"],"User-Agent":["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"],"Sec-Fetch-Mode":["no-cors"],"Sec-Fetch-Site":["same-origin"],"X-Forwarded-For":["172.69.166.62"]}},"bytes_read":0,"user_id":"","duration":0.003496731,"size":0,"status":304,"resp_headers":{"Server":["Caddy"],"Vary":["Accept"],"Cache-Control":["public, max-age=60, must-revalidate"],"Etag":["wAFeNmUP3wKPuE2AIFkQ+VNq9y67yy5adScnSnOdbGk="],"Date":["Sat, 20 Jan 2024 02:03:11 GMT"]}}
{"level":"info","ts":1705716191.105501,"logger":"http.log.access.log0","msg":"handled request","request":{"remote_ip":"172.18.0.2","remote_port":"47256","client_ip":"172.18.0.2","proto":"HTTP/1.1","method":"GET","host":"www.treblesolutions.com","uri":"/api/get-rates","headers":{"Accept":["*/*"],"Cdn-Loop":["cloudflare"],"Cf-Visitor":["{\"scheme\":\"https\"}"],"Referer":["https://www.treblesolutions.com/en"],"Sec-Fetch-Dest":["empty"],"X-Forwarded-For":["172.69.166.62"],"User-Agent":["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"],"X-Forwarded-Host":["www.treblesolutions.com"],"Priority":["u=1, i"],"Sec-Ch-Ua":["\"Not_A Brand\";v=\"8\", \"Chromium\";v=\"120\", \"Google Chrome\";v=\"120\""],"Sec-Ch-Ua-Platform":["\"macOS\""],"Sec-Fetch-Site":["same-origin"],"X-Forwarded-Proto":["https"],"Accept-Encoding":["gzip"],"Cf-Connecting-Ip":["2406:3003:2073:38a5:1124:4606:4097:e729"],"Sec-Ch-Ua-Mobile":["?0"],"Sec-Fetch-Mode":["cors"],"Accept-Language":["en-US,en;q=0.9,ja;q=0.8"],"Cf-Ipcountry":["SG"],"Cf-Ray":["8483bd523c43495f-SIN"],"Cookie":[]}},"bytes_read":0,"user_id":"","duration":0.004234091,"size":381,"status":200,"resp_headers":{"Vary":["RSC, Next-Router-State-Tree, Next-Router-Prefetch, Next-Url"],"X-Nextjs-Cache":["HIT"],"Server":["Caddy"],"Content-Type":["application/json"],"Date":["Sat, 20 Jan 2024 02:03:11 GMT"]}}
{"level":"info","ts":1705716191.2107377,"logger":"http.log.access.log0","msg":"handled request","request":{"remote_ip":"172.18.0.2","remote_port":"47262","client_ip":"172.18.0.2","proto":"HTTP/1.1","method":"GET","host":"www.treblesolutions.com","uri":"/en?_rsc=16ipr","headers":{"Cf-Connecting-Ip":["2406:3003:2073:38a5:1124:4606:4097:e729"],"User-Agent":["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"],"Cf-Visitor":["{\"scheme\":\"https\"}"],"If-None-Match":["W/\"us3a73pcnej1k\""],"Next-Router-Prefetch":["1"],"Referer":["https://www.treblesolutions.com/en"],"X-Forwarded-Proto":["https"],"Accept-Encoding":["gzip"],"Cdn-Loop":["cloudflare"],"Cookie":[],"Next-Url":["/en"],"Priority":["u=1, i"],"Sec-Ch-Ua":["\"Not_A Brand\";v=\"8\", \"Chromium\";v=\"120\", \"Google Chrome\";v=\"120\""],"X-Forwarded-Host":["www.treblesolutions.com"],"Accept-Language":["en-US,en;q=0.9,ja;q=0.8"],"Cf-Ipcountry":["SG"],"Next-Router-State-Tree":["%5B%22%22%2C%7B%22children%22%3A%5B%22en%22%2C%7B%22children%22%3A%5B%22__PAGE__%22%2C%7B%7D%5D%7D%5D%7D%2Cnull%2Cnull%2Ctrue%5D"],"Sec-Fetch-Site":["same-origin"],"Cf-Ray":["8483bd525c5a495f-SIN"],"Rsc":["1"],"Sec-Ch-Ua-Mobile":["?0"],"Sec-Fetch-Dest":["empty"],"Sec-Fetch-Mode":["cors"],"X-Forwarded-For":["172.69.166.63"],"Accept":["*/*"],"Sec-Ch-Ua-Platform":["\"macOS\""]}},"bytes_read":0,"user_id":"","duration":0.007993782,"size":0,"status":304,"resp_headers":{"Server":["Caddy"],"Vary":["RSC, Next-Router-State-Tree, Next-Router-Prefetch, Next-Url"],"X-Nextjs-Cache":["HIT"],"Cache-Control":["s-maxage=31536000, stale-while-revalidate"],"Etag":["\"us3a73pcnej1k\""],"Date":["Sat, 20 Jan 2024 02:03:11 GMT"]}}
{"level":"info","ts":1705716191.777225,"logger":"http.log.access.log0","msg":"handled request","request":{"remote_ip":"172.18.0.2","remote_port":"47256","client_ip":"172.18.0.2","proto":"HTTP/1.1","method":"GET","host":"www.treblesolutions.com","uri":"/?_rsc=16ipr","headers":{"Accept-Encoding":["gzip"],"Cf-Visitor":["{\"scheme\":\"https\"}"],"Next-Url":["/en"],"Sec-Ch-Ua":["\"Not_A Brand\";v=\"8\", \"Chromium\";v=\"120\", \"Google Chrome\";v=\"120\""],"X-Forwarded-For":["172.69.166.63"],"X-Forwarded-Proto":["https"],"Sec-Fetch-Dest":["empty"],"X-Forwarded-Host":["www.treblesolutions.com"],"Cookie":[],"Sec-Fetch-Site":["same-origin"],"Priority":["u=1, i"],"Sec-Ch-Ua-Platform":["\"macOS\""],"Rsc":["1"],"User-Agent":["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"],"Accept":["*/*"],"Cf-Ipcountry":["SG"],"Next-Router-Prefetch":["1"],"Next-Router-State-Tree":["%5B%22%22%2C%7B%22children%22%3A%5B%22en%22%2C%7B%22children%22%3A%5B%22__PAGE__%22%2C%7B%7D%5D%7D%5D%7D%2Cnull%2Cnull%2Ctrue%5D"],"Referer":["https://www.treblesolutions.com/en"],"Accept-Language":["en-US,en;q=0.9,ja;q=0.8"],"Cdn-Loop":["cloudflare"],"Sec-Fetch-Mode":["cors"],"Cf-Connecting-Ip":["2406:3003:2073:38a5:1124:4606:4097:e729"],"Cf-Ray":["8483bd525c57495f-SIN"],"Sec-Ch-Ua-Mobile":["?0"]}},"bytes_read":0,"user_id":"","duration":0.577719456,"size":3,"status":307,"resp_headers":{"Server":["Caddy"],"Location":["/en"],"Date":["Sat, 20 Jan 2024 02:03:11 GMT"]}}
{"level":"info","ts":1705716191.8406212,"logger":"http.log.access.log0","msg":"handled request","request":{"remote_ip":"172.18.0.2","remote_port":"47256","client_ip":"172.18.0.2","proto":"HTTP/1.1","method":"GET","host":"www.treblesolutions.com","uri":"/en","headers":{"Cookie":[],"Next-Router-Prefetch":["1"],"Sec-Ch-Ua-Mobile":["?0"],"X-Forwarded-Proto":["https"],"Cf-Connecting-Ip":["2406:3003:2073:38a5:1124:4606:4097:e729"],"Sec-Ch-Ua-Platform":["\"macOS\""],"Sec-Fetch-Mode":["cors"],"Accept-Encoding":["gzip"],"Next-Url":["/en"],"Priority":["u=1, i"],"Rsc":["1"],"Sec-Fetch-Site":["same-origin"],"User-Agent":["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"],"Sec-Fetch-Dest":["empty"],"X-Forwarded-Host":["www.treblesolutions.com"],"Cf-Ray":["8483bd56d892495f-SIN"],"Cf-Visitor":["{\"scheme\":\"https\"}"],"Cdn-Loop":["cloudflare"],"Cf-Ipcountry":["SG"],"Sec-Ch-Ua":["\"Not_A Brand\";v=\"8\", \"Chromium\";v=\"120\", \"Google Chrome\";v=\"120\""],"X-Forwarded-For":["172.69.166.62"],"Accept":["*/*"],"Next-Router-State-Tree":["%5B%22%22%2C%7B%22children%22%3A%5B%22en%22%2C%7B%22children%22%3A%5B%22__PAGE__%22%2C%7B%7D%5D%7D%5D%7D%2Cnull%2Cnull%2Ctrue%5D"],"Referer":["https://www.treblesolutions.com/en"],"Accept-Language":["en-US,en;q=0.9,ja;q=0.8"]}},"bytes_read":0,"user_id":"","duration":0.003025826,"size":6118,"status":200,"resp_headers":{"Vary":["RSC, Next-Router-State-Tree, Next-Router-Prefetch, Next-Url, Accept-Encoding"],"X-Nextjs-Cache":["HIT"],"Cache-Control":["s-maxage=31536000, stale-while-revalidate"],"Etag":["\"us3a73pcnej1k\""],"Content-Encoding":["gzip"],"Server":["Caddy"],"Content-Type":["text/x-component"],"Date":["Sat, 20 Jan 2024 02:03:11 GMT"]}}

Thank you.

One more thing now website is getting only after hit the www.treblesolutions.com
but without www it’s not working how can i overcome this issue?

Those are two separate domains. You need to configure both in your Caddyfile.

1 Like

Thank you @francislavoie all sorted now,

1 Like

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