Proxy URL not loading site?

Hi, total amateur here,

I’m just getting started with proxying…and can’t seem to get sonarr to load properly and I’m confused why, sabzbd loads fine.

https://mainframe.rulinglife.com/sonarr

the url just spits out Sonarr Ver.

proxy /sonarr http://192.168.178.5:8989 { # https://sonarr.tv/
transparent
}

Hi @robertgranholm, welcome to the Caddy community. We all started somewhere!

In this case, you’ve run straight into one of the most prevalent obstacles people face when trying to reverse proxy apps - the “subfolder problem”. You’ll hit this regardless of what program you use as a reverse proxy, because it’s a logical problem, not a bug in the web server or the app itself.

Just about every app is written under the assumption that it is being served at the web root, i.e. example.com/ - but in your case, it isn’t. You’re only serving it at example.com/sonarr.

So when the app tries to serve you CSS and JS assets, which it needs to render the site, it tells your browser to grab /foo.css and /bar.js instead of /sonarr/foo.css and /sonarr/bar.js. Caddy doesn’t know it has to forward these on to Sonarr, so it throws back a 404, and your app doesn’t render properly.

Sonarr actually has a setting you can use to configure the subfolder - like most apps that are configurable in this way, the setting is referred to as a “URL base”. You can find it at http://192.168.178.5:8989/settings/general - in your case, set it to /sonarr and then go to System and restart the app.

For apps that don’t have a URL base option, your only (edit: straightforward, at least, other methods are possible but difficult and complicated) workaround is to serve them on a subdomain instead of a subfolder and let them have their assumed web root.

1 Like

Hrmm, okay, so learning curve here. I don’t have a problem persay with making the services subdomains…but the main url is already a subdomain…would I need to rework that alltogether?

Back to testing and documentation I guess

Thanks for the context, that helped!

You can make a subdomain of your subdomain, if you wanted! E.g. service_name.mainframe.rulinglife.com

Just make sure the DNS records are set and you’re, well, all set.

One trick I like to use, is for a given host (lets call it myhost), set a wildcard DNS record as a CNAME: *.myhost.whitestrake.net to myhost.whitestrake.net.

Then everything that’s a subdomian of myhost.whitestrake.net points to myhost by default and I don’t need to add records every time I think about setting up a new service.

Woah, I think you just blew my mind with a subdomain of a subdomain. I’ve never set one of those up before. So this domain is on Google Domains, and since mainframe.rulinglife.com is going to a home server, it’s setup with Dynamic DNS through DNS O Matic.

However I don’t think that matters, if I setup *.mainframe.rulinglife.com to go to mainframe.rulinglife.com …it’ll all hit my server, however how does caddy know what to do with it…will caddy pick up if the url matches a service it has defined and then route properly from there?

Hmm this doesn’t seem right…

You just put the URLs you want Caddy to handle in the Caddyfile!

Like:

service1.mainframe.rulinglife.com {
  proxy / service1
}

service2.mainframe.rulinglife.com {
  proxy / service2
}

If you want to catch all the stragglers for random sub-subdomains you aren’t expecting, you can do that:

*.mainframe.rulinglife.com {
  redir https://google.com

  # Maybe grab a wildcard cert so this just works for HTTPS regardless of the hostname?
  # tls {
  #   dns cloudflare
  # }
}

Looks good to me. The first column is actually *.mainframe.rulinglife.com., the panel is just omitting the rulinglife.com because that’s the Registered Domain, it’s implied.

Although, actually, it looks like it’s CNAME’d to rulinglife.com instead of mainframe.rulinglife.com.

Hmm cool, alright, that’s in place, now to play around and test it. Thanks

So when I do a look up, it’s returning the IP for the main domain, rulinglife.com which is on Google Domains for whatever they put up for a website … not the subdomain mainframe.rulinglife.com which is my IP from my ISP routing to my home server.

Yeah the CNAME target definitely needs to be mainframe.rulinglife.com, not rulinglife.com. Double check the CNAME target in your DNS control panel.

1 Like

Got it figured, thanks x10! Onward to the testing fun…after work…tonight… : )

1 Like

So I understand how the wildcard works and the sub sub domain.

So, since the services can have their “roots” and I can access those via the subsubs…I just need to tell caddy about it…right?..something like this?

proxy sonar.mainframe.rulinglife.com http://192.168.178.5:8989 {          # https://sonarr.tv/
    transparent
}

I shouldn’t need to mess with the settings on the actual services right? Or should I go say, use HTTPS and give them the caddy enabled subsubdomain addresses?

That’s not it, tried this but that’s not working either…

sonarr.mainframe.rulinglife.com {
proxy /http://192.168.178.5:8989 # https://sonarr.tv/
transparent
}

Should there be a space there that’s missing?

Have a read of the proxy docs. Your second try is the one that looks closest to what you should be using.

https://caddyserver.com/docs/proxy

I tried that as well, got this error.

2019/04/04 08:05:26 Caddyfile:132 - Error during parsing: Unknown directive ‘sonarr.mainframe.rulinglife.com

I’ll see if there’s mention of that error in the docs.

Hmm so I read through the proxy page but not much applied.

I think it’s in defining what to proxy, is caddy seeing sonarr.mainframe.rulinglife.com as a different site maybe? so I need to define this outside the primary `nmainframe.rulinglife.com

{ ` opener? … I’ll try that

No that didn’t work but I think it has something to do with the domains being different…the new subdomains, do I need to define them separately from the first I was using…with separate root paths?

Figured out my brackets which I think were causing the issue but now my domain lookups aren’t working when they were yesterday! Hmmpph!

mediacenterserver:caddy mediacenter$ sudo caddy

Activating privacy features... 2019/04/04 09:20:14 [INFO] [sonarr.mainframe.rulinglife.com] acme: Obtaining bundled SAN certificate

2019/04/04 09:20:16 [INFO] [sonarr.mainframe.rulinglife.com] AuthURL: https://acme-v02.api.letsencrypt.org/acme/authz/gGkfS4VJGExWQmLw1VFqXeszK0SLWmP5vnz2PwT5JkM

2019/04/04 09:20:16 [INFO] [sonarr.mainframe.rulinglife.com] acme: use tls-alpn-01 solver

2019/04/04 09:20:16 [INFO] [sonarr.mainframe.rulinglife.com] acme: Trying to solve TLS-ALPN-01

2019/04/04 09:20:22 [sonarr.mainframe.rulinglife.com] failed to obtain certificate: acme: Error -> One or more domains had a problem:

[sonarr.mainframe.rulinglife.com] acme: error: 400 :: urn:ietf:params:acme:error:dns :: DNS problem: NXDOMAIN looking up A for sonarr.mainframe.rulinglife.com, url:

and I have this for my DNS settings still…

Got it! Google actually wanted *.mainframe and routing it to mainframe.ruling.life odd, but got it working…onward!