Troubles setting up Caddy for Laravel inside a Docker

(Joseph Levarato) #1

I’m having a lot of trouble to setup Caddy for Laravel 5. My goal is to be able to log on the server, run curl localhost and get my website’s html as a response. The goal later is just to have a domain name that will redirect to this server.

The website is inside a Docker container, that links the port 80 inside to the port 80 outside.

I checked the configuration proposed in the Caddy’s Github, however I didn’t understand how I should use things such as FastCGI. I ended up removing them because it caused issues (ie, 502 - bad gateway, or simply a 404)

Here is my Caddyfile: {
  root /var/www/html/my-project/public
  tls off

  rewrite {
    to {path} {path}/ /index.php?{query}

I removed tls because the server already handles the HTTPS, so no need to ask for two certificates. However, with this configuration, I get “404 Not Found” without understanding what’s wrong.

Any help is welcome

Thanks in advance

(Matthew Fay) #2

Hi @Drillan767,

My first thought is… does the index file in /var/www/html/my-project/public exist, readable by Caddy?

I just did a quick test with caddy -host -port 2015 and ran curl -IX GET localhost:2015, got a 404 like you said you’re getting.

Ran it again with caddy -host -port 2015 "status 200 /" and got a 200 response this time.

(Joseph Levarato) #3

Hello, thanks for your reply, and I apologize for the time it took to answer. I also tried your command, but how should I adapt it to a Dockerfile?

For now, I just run “caddy”, with the Caddyfile in the “my-project” directory (that does exist, is chown as www-data:www-data and has a chmod 777 on it). This “status 200 /” seems to make everything work, but is there a way to adapt it in the Caddyfile configuration?

(Matthew Fay) #4

It’s not there to make anything work, it’s just to explain how I tested it to demonstrate that it wasn’t an issue with your hostname, it was an issue with finding a file to serve.

If you’re requesting /, Caddy will try to serve an index. If there’s no index file in the web root, it’s going to find nothing to serve, and it’ll issue a 404 instead.