Caddy not serving website

1. The problem I’m having:

I’m trying to replace my nginx server with caddy to server my ui service. I tried to add everything I have nginx.conf to my caddyfile. When I deploy my changes to QA, the browser returns no response for me. I can’t see where the error can be or related to what. I’m using docker to build my app and set the caddy server up

2. Error messages and/or full log output:

3. Caddy version:

v2.7.4

4. How I installed and ran Caddy:

a. System environment:

Docker

b. Command:

PASTE OVER THIS, BETWEEN THE ``` LINES.
Please use the preview pane to ensure it looks nice.

c. Service/unit/compose file:

Docker file

# Stage 1
FROM node:18 as react-build
WORKDIR /app
COPY . ./
ENV NODE_OPTIONS="--max-old-space-size=8192"
RUN curl -u  packurl
RUN yarn
RUN yarn build

# Stage 2 - the production environment
FROM caddy:latest

COPY --from=react-build /app/dist /usr/share/caddy/html
COPY Caddyfile /etc/caddy/Caddyfile

EXPOSE 8080

CMD ["caddy", "run", "--config", "/etc/caddy/Caddyfile"]

d. My complete Caddy config:

{
	http_port 8080
}
localhost:8080 {
	
	root * /usr/share/caddy/html
	file_server

	metrics /prometheus

	header {
		X-XSS-Protection "1; mode=block"
		Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
		X-Frame-Options SAMEORIGIN
		X-Content-Type-Options nosniff
		Content-Security-Policy "frame-ancestors 'none'"
		Access-Control-Allow-Origin "*"
		Access-Control-Allow-Credentials true
		Access-Control-Allow-Methods "GET, HEAD, POST, PUT, OPTIONS, MOVE, DELETE, COPY, LOCK, UNLOCK, PROPFIND, MKCOL"
		Access-Control-Allow-Headers "Authorization,DNT,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,X-Accept-Charset,X-Accept,origin,accept,if-match,destination,overwrite,X-CustomHeader"
	}
	# Handle /health endpoint
	route /health {
		respond "UP"
	}
	
}


5. Links to relevant resources:

1 Like

I’d recommend putting your files in /srv instead of /usr/share/caddy. The /usr/share directory is meant for package files, not for a user’s own files. See https://tldp.org/LDP/Linux-Filesystem-Hierarchy/html/usr.html which explains.

You haven’t shown in what way it’s not working. Enable the debug global option, and show Caddy’s logs. Caddy writes its logs to stdout, so you can run docker logs <your-caddy-container-id> to get them.

Make a request with curl -v, show what you get.

1 Like

The requests made with curl are returning the expected data, health is up, prometheus is working, and html file is returned. The problem is with browser that shows no UI. Also when I deploy I noticed that there is no request is made to the server. Could the problem be with the host name or the port I’m using?

1 Like

Is the request made with curl the exact same that the browser is making?

Yes both are http://localhost:8080 or http://localhost:8080/health for example

but didn’t try to curl the website URL itself after deployment

Please do that. Using curl will show us what you’re seeing.

Tried now with curl and it returns the normal HTML, it’s the same as what is returned from doing curl website url when I use nginx

Then I don’t know what to tell you. You haven’t shown the actual problematic behaviour at all, so we can’t help.

1 Like

I just think that showing the HTML won’t help it’s just a sign in page that is secured with oauth2-proxy. what may help for example is on browser the network tab shows no requests made to the server

Then that sounds like a javascript issue or something, not a problem with Caddy.

Again, without actual evidence of a problem, I don’t see what we can do to help here.

1 Like

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