Too Many Redirect Help with #munkireport

Hello!

I’m running into a “too many redirects error” when trying to get munkireport with php up and running with Caddy. MunkiReport is a php web application, their one page on server setup is here → Server setup · munkireport/munkireport-php Wiki · GitHub

I’ve searched the forums and it seems there’s only a few munkireport posts but I couldn’t find anything useful, here’s my caddyfile info.

example.com {
root /Volumes/MediaExtend/Munki/munkireport/public
tls example@gmail.com
proxy / http://192.168.178.4 { transparent }
# PHP-FPM Configuration for Caddy
fastcgi / /run/php/php7.2-fpm.sock php {
ext .php
split .php
index index.php
}
}

I am getting too many redirects which would make me think the root is wrong? Help appreciated, thanks!

Hi @robertgranholm!

The most common cause of this issue, by a huge margin, is when the backend issues redirects to HTTP while Caddy is still trying to enforce HTTPS usage.

Try running curl -IL http://192.168.178.4 on your Caddy host and posting the output, it’ll tell us a bit about what the backend is doing when Caddy proxies to it.


P.S. you’ve got a global proxy / and a global fastcgi / - both of them are configured to act on every request, but only one will ever do anything, and that’s proxy, because it executes first and then finishes the request. With that setup, you can completely remove fastcgi and there will be no difference.

The root is similarly completely redundant as all requests are handled by the proxy - no request ever makes it to Caddy’s static file server.

The following is functionally identical to your Caddyfile above:

example.com {
  tls email@example.com
  proxy / http://192.168.178.4 {
    transparent
  }
}

P.S.S. Don’t use @gmail.com addresses as examples, someone might own that address! Use the example domain.

1 Like

Thanks for the reply.

Okay, so I am removing proxy since I don’t think munkireport plays well with that, it doesn’t load by going to that IP address anyway, as far as I know looking at the munkireport info, it’s just flat files sitting in that folder, not something already running on an internal ip, so thinking it through, of course that wouldn’t work.

However, when I remove the proxy, I get a 502 error.

So I have this now, and get a 502 error, the path is valid, when I paste it in the Finder, it goes to the right location.

example.com {
log
root /Volumes/MediaExtend/Munki/munkireport/public
tls example@example.com

# PHP-FPM Configuration for Caddy
 fastcgi / /run/php/php7.2-fpm.sock php {
     ext .php
     split .php
	 index index.php
 }	

}

The files in that folder are what’s below.

web.config
index.php
assets
.htaccess

I feel like I’m missing something obvious. I have only ever started up a webserver with .html type files or something like Sonarr, with an app that runs a local server first accessible via IP and then I use caddy to proxy. In this case I am using Caddy to actually run the PHP server side of things, at least that’s what was my intention, am I thinking about it all wrong?

I took this line from another forum post…

fastcgi / /run/php/php7.2-fpm.sock php {

I thought that this told Caddy to use some in built PHP serving capabilities, is this wrong? Is it looking for a run/php folder in my root and expecting some PHP server running? If so, how do I get that accomplished on the Mac? Sorry for my lack of knowledge here, I am trying to learn.

PS. Thanks for the correction on email address.

Yeah, I did think the proxy was a bit odd.

You don’t need the entire block after the FastCGI line. Just fastcgi / /run/php/php7.2-fpm.sock php on its own works. The php on the end quite literally is shorthand for the ext, split, and index subdirectives you’re setting manually.

So basically what’s happening now is that instead of proxying, Caddy is trying to find the file you’re requesting (probably the index.php file, yeah?) and ship it off to PHP-FPM for script processing (Caddy itself doesn’t process PHP). It’s looking to ship that file over to /run/php/php72-fpm.sock and it’s hoping for a fully processed response body in return, basically. Something is going wrong at this stage.

Given this statement in particular:

Did you take that line verbatim? Because that middle part, /run/php/php72-fpm.sock - the location of the PHP-FPM listener - changes completely depending on the environment. Like, they’ll be in completely different locations on some servers, or there wont even be a socket because it’s not configured by default and it’ll be listening on localhost:9000 instead.

So if you didn’t manually set up PHP-FPM yourself, and don’t know where its listener is, you’d need to find that out and point Caddy at that instead - because pointing at a listener that doesn’t exist is indeed one very plausible explanation for the 502 errors you’re getting.

Thank you in helping me understand, much appreciated! I will get to work on the PHP side of things, getting that server and listener up and running and report back. Cheers : )

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