Reverse Proxy setup on Pi3

Hi all,

I’m a newbie on caddy but, thanks to another user, I successfully installed caddy on my Pi3 to use it as reverse proxy for my webservices.

But I can’t figure out how to make it works!

Here’s my caddyfile setup:

domain.com{
proxy /plex xxx.xxx.x.100:32400 {
transparent	
websocket
}
tls admin@domain.com
}

{
proxy /dsm xxx.xxx.x.100:5001 {
transparent	
websocket
}
tls admin@domain.com
}

{
proxy /jarvis xxx.xxx.x.200:8123 {
transparent	
websocket
}
tls admin@domain.com
}

But regardless of url I only see the defaut page with the default 404 message:

Can someone please help me?

Thank you in advance

That doesn’t look like a valid Caddyfile, there are server blocks with no labels.

I’m also not seeing a root, so for requests other than the proxy base paths, Caddy will just try to serve files out of the directory it was run from. If there’s no index files there, it will give you HTTP 404 errors.

First of all thank you for your support.

I’ve modified caddyfile with your suggestion. Here it is:

domain.com
{
root /var/www/html
}

domain.com/plex
{
proxy /plex xxx.xxx.x.xxx:32400/web/ {
transparent 
websocket
}
tls admin@domain.com
}
domain.com/dsm
{
proxy /dsm xxx.xxx.x.xxx:5001 {
transparent 
websocket
}
tls admin@domain.com
}
domain.com/homeassistant
{
proxy /homeassistant xxx.xxx.x.xxx:5123 {
transparent 
websocket
}
tls admin@domain.com
}

As you may notice I added a domain for root and now I’m able to connect to a default landing page on the Pi3.

No luck for the other setting. I always receive a 404 error. And as you may notice I changed url for plex for the index.html location.

Can you please help me?

Thank you in advance

What is the path to your Caddyfile? And how are you running caddy, and from which folder?

Caddyfile is on path /home/pi so to run it I just digit “caddy” from ssh prompt.

I see a few problems here.

Firstly, you’re proxying from /plex under example.com/plex, and you have no root in this definition block. That means to be routed to the upstream you need to request example.com/plex/plex, which I doubt is intended behaviour. A request for example.com/plex will be 404’d.

You could just throw all these proxies in the same definition block, no need for labels with subfolders.

example.com {
	root /var/www/html
	tls admin@example.com
	proxy /dsm upstream:5001 {
		transparent
		websocket
	}
	proxy /homeassistant upstream:5123 {
		transparent
		websocket
	}
	...
}

Secondly, Plex isn’t going to play nicely under /plex. It wants /web and a whole lot of other folders too. My strong suggestion is to give it the site root of a subdomain instead. You might have some luck getting it working, but it will be a complicated setup.

Ok!

I followed your suggestion and moved to subdomain (more easy!)

here is the new version:

domain.com
{
root /var/www/html
}

plex.domain.com {
proxy / xxx.xxx.x.100:32400 {
transparent
websocket
}
tls admin@domain.com
}

dsm.domain.com {
proxy / xxx.xxx.x.100:5000 {
transparent
websocket
}
tls admin@domain.com
}

homeassistant.domain.com {
proxy / xxx.xxx.x.200:8123 {
transparent
websocket
}
tls admin@domain.com
}

It works for plex and for home assistant. No lucky for Synology DSM instead.

Do you know if I should add something?

Thank you

I’m not sure. What you’ve got there looks good, generally speaking. Can you curl -i xxx.xxx.x.100:5000 successfully from the Caddy host? What output do you get curl dsm.example.com?

GOTCHA!

The issue was generated from the automatic redirect from http to https (in control Panel - DSM setting).

I just unflagged “automatically redirect HTTP to HTTPS” and now it works! :slight_smile:

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