Caddyfile prefix missing

1. The problem I’m having:

when I try my container (there is a caddy server and a react frontend) locally with localhost:80 , I have no problem but in K8S under an ingress ( aws load balancer ) I have a problem :

I can curl from internet the pod

curl https://mywebsite.io/project_A/

BUT it show an empty page ( blank )

and the firefox console show errors

GET
https://mywebsite.io.io/static/js/main.acbe4637.js
[HTTP/2 503 Service Unavailable 4ms]

GET
https://mywebsite.io.io/static/css/main.acb135df.css
[HTTP/2 503 Service Unavailable 4ms]

Loading failed for the <script> with source “https://mywebsite.io.io/static/js/main.acbe4637.js”. behavior:1:460
GET
https://mywebsite.io.io/logo192.png
[HTTP/2 503 Service Unavailable 0ms]

GET
https://mywebsite.io.io/favicon.ico
[HTTP/2 503 Service Unavailable 0ms]

but if I manually curl the https://mywebsite.io/project_A/logo192.png it work ( show the react logo )

so all the urls are missing the prefix_path , how can I solve this ? thank you

2. Error messages and/or full log output:

no error in the logs of the container

3. Caddy version:

v2.6.4 h1:2hwYqiRwk1tf3VruhMpLcYTg+11fCdr8S3jhNAdnPy8=

4. How I installed and ran Caddy:

using the docker image caddy:alpine

a. System environment:

EKS 1.26

b. Command:

no custom of the entrypoint of the caddy:alpine container

c. Service/unit/compose file:

d. My complete Caddy config:

{
  auto_https disable_redirects
}


:80 {
    handle_path /api/* {
        reverse_proxy {$BACKEND_API_HOSTNAME}:{$BACKEND_API_PORT} {
            header_up Host {upstream_hostport}
            header_up X-Real-IP {remote_addr}
            header_up X-Forwarded-Host {host}
        }
    }

    handle {
            rewrite * /project_A/{uri}
            root * /usr/share/caddy/
            
            try_files {path} {file} /index.html
            file_server
    }
}

it look like that the line

            rewrite * /project_A/{uri}

is incorrect or not working , thank you for the help

This adds /project_A to the path.

It sounds like you want to remove /project_A.

For that, you should use handle_path.

Caddy would not respond with a 503 unless it hit reverse_proxy, but your config does not suggest it could have. I think something else is going on.

thank for your answer , I was not explicit

the url https://mywebsite.io/project_A/ is correct

cause my ingress is

spec:
  rules:
    - host: mywebsite.io
      http:
        paths:
          - path: /project_A
            pathType: Prefix
            backend:
              ...

what is incorrect is the fact that the react code is not aware of the prefix ( all the url in the html are missing the prefix )

does it make sence ? thank you again for your help

Then you need to configure it to be aware. There should be a basePath config option or similar in your build tooling.

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