Caddy to emby returns 502 bad gateway (SOLVED!)

Hi all!

Im having trouble getting caddy reverse proxy to my Emby media server. When i visit the subdomain for emby it returns a 502 bad gateway but the IP address in the caddy file is definilty the correct one (inside my home network everything works as it should).

My caddyfile as it is now, removed the things i tested and didnt work.

cloud.domainname.nl {
                root /var/www/caddy
                gzip
}

emby.domainname.nl {
                proxy / 192.168.1.3:8096 {
                        transparent
                        websocket
                }

}

website.domainname.nl {
                tls mail@maildomain.nl
                root /var/www/website
                gzip
                fastcgi / /run/php/php7.0-fpm.sock php
                rewrite {
                         if {path} not_match ^\/wp-admin
                        to {path} {path}/ /index.php?_url={uri}
                }

}

I tried the following so far, without luck:

I couldnt find any logging or sites that pointed me in the direction where to find it. When i use the yournalctl command it returns notting usefull, no errors just that its serving the websites listed in my config. Its not returning any response when i visit the emby subdomain. When i visit the others, which all work, i see things happen in the log.

Howdy @miesjel, welcome to the Caddy community!

Looks like you’ve given it a pretty good effort so far. Just to address some of your attempts:

That can cause 502s - but it looks like you’re proxying to HTTP (the scheme http:// is implicit for any URL that doesn’t specify - i.e. http://192.168.1.3:8096), so this one can’t be our culprit.

Also not a bad try, but in this user’s case, he was actually hosting Organizr directly via Caddy+PHP, and it was Organizr that was dying, not one of his proxies - making this less likely to be the culprit, too.

Another point against this being the likely fix is the fact that you’d have both FastCGI and a proxy running. Only one of those will ever run at any given time - both of those plugins end the request process by returning content to the client. If you ever have both going at the same time, proxy wins every time and FastCGI never operates because of the order of middleware execution.


OK, now lets get to troubleshooting. First step is to gather some information, and there’s two ways to go that should tell us a bit about what might be going wrong.

  1. From a shell on the Caddy host, run the command: curl -ILX GET 192.168.1.3:8096
    This will tell us, most likely, what kind of HTTP response Caddy is getting from Emby. If there’s any major issues here, we’ll spot them pretty quick. Post the full output of the command.

  2. Add logging directives to the Emby subdomain: log stdout and errors stdout.
    You’re running Caddy via systemd, so stdout will put that info in journalctl. You can substitute /path/to/log.file for stdout if you’d prefer to tail a file. Once those directives are in, bring Caddy up, make some requests that result in 502s, then go check the log. We’re looking for 502 error messages accompanying the requests - post the lot.

Once we have that info, we’ll know where to start looking to fix the problem.

1 Like

Hi there!

Thanks for explaining why my options didn’t help, learned something new!

I’ve done as asked and found the problem! There is no route to host, or in other words i cant ping my host from my caddy server.

I’ve done some testing and it seems i am not able to ping it from other Linux servers as well. Emby is running on a Windows server 2016 server. When i ping from Win10 devices I have no problems.

I’m looking in to this strange problem, but haven’t found the solution yet.

1 Like

Problem solved!

Thanks @Whitestrake for pointing me in the right direction!

For others, here is some info, hope it will help!

The problem was that I could not ping from my caddy server to the server running Emby.

The server running Emby is a Windows server 2016 machine with hyper v. In that hyper-v I have a VM for caddy and a couple of other VM’s, but Emby is running locally. I could not ping from any VM to the host IP address.

After some troubleshooting I decided to remove the virtual switch from Hyper-V and reconfigure it. Rebooted the VM’s and everything started working, including Emby!

1 Like

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