Use Rasperry with HA on it as NGINX Reverse Proxy

I’ve changed the settings but I still receive errors:

Caddyfile:6 - Parse error: Wrong argument count or unexpected line ending after '[email protected]

This is the new caddyfile

domain.com
{
proxy /plex xxx.xxx.xxx:32400 {
transparent	
websocket
} tls [email protected]
}

Thank you!

Try:

domain.com {
proxy /plex xxx.xxx.xxx:32400 {
transparent
websocket
}
tls [email protected]
}

Remember you need port 80 and 443 directed at your pi for let’sencrypt to work.

1 Like

one step forward.

Now the caddyfile works but every setup bring me to the default page with the defaul message “404 Not Found” as when caddy was on port 2015!

I think with plex you might have to browse to /plex/index.html plex is a special case I believe.

Ive not tried proxy in plex as I have plex pass. Every other service I’ve proxies works though.

I have Plex Pass too. Why don’t you need to proxy it?

Btw I also added others situations:

proxy /dsm xxx.xxx.xxx:5000 (my synology nas)
proxy /jarvis xxx.xxx.xxx:5123(my pi3 with HA on it)

but the only page i can see is to the default one with “404 Not Found”

Give this a shot:

proxy /blog localhost:2002 {
without /blog
}

i.e add the without parameter. Thus will proxy without adding /blog to all the URLs.

Oh also did you run the set cap command to allow caddy access to bind to the right ports? If not worth trying that first. Should be in the Ubuntu guide I linked. I will also stress I run caddy on a separate Ubuntu server not on the Pi itself so I may now become of limited use.

Also make sure you have your domain name set to forward to your home ip. I found I had most luck not using subdirectory, but setting a dedicated subdomain for each service.

Plex pass will do the reverse stuff for you so I just login at plex.tv rather than proxy my own instance.

First of all thank you again for your effort.

I tried to add proxy /blog but nothing changed.

Please notice that the 404 error is not from the browser, but from caddy!

It’s the same that you see when you install caddyserver. Please look at the link http://imgur.com/a/5cGJM

So I think I can connect from the web to my pi but then nothing is routed with the proxy.

Finally thank you for your explaination on plex. But at work plex is blocked so I was searching a solution to see tv shows at lunch time!

Not trying to be silly here, but it’s often the simple things we miss. Can your pi actually see the services it’s trying to load from? I.e if you use iptables or something similar, are they opened on those ports at the destination? What OS are the services you are trying to proxy running on? Does that itself run a firewall and is that open? Looks like caddy is working but can’t find the right file to load at this point.

Uhm I think I did’t understand your first question.

Right now everything works fine if I try to connect to services without using caddy. For example I can connect to dsm.domain.com:5001 without any problem right now. The same for other services. The error happens only if I try to connect to it using caddy: domain.com/caddy

Other answer are:
plex and dsm are on my synology nas
home assistant is on the same rasperry pi where caddy is running.
No firewall installed or running on Pi (as far as I know).

Ok. So home assistant is local to the pi. And you have I assume set the relevant configuration in the http component. If all this is done, try to only proxy HA. If that works we know there’s something you need to do on the Synology.

No changes.

I managed to land on a fake default page. But no luck for proxy servers.

Here is the new caddyfile

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

domain.com/plex
{
proxy /plex xxx.xxx.x.xxx:32400/web/ {
transparent 
websocket
}
tls [email protected]
}
domain.com/dsm
{
proxy /dsm xxx.xxx.x.xxx:5001 {
transparent 
websocket
}
tls [email protected]
}
domain.com/homeassistant
{
proxy /homeassistant xxx.xxx.x.xxx:5123 {
transparent 
websocket
}
tls [email protected]
}

There is stil some difference from your working configuration?

Mine uses subdomains for each. And you need new lines between each configuration.

Can you copypast and example so I can put in my caddyfile and see what happens?

I use this:

sub.domain.com {
proxy / 192.168.x.x:nnnn {
transparent
}
tls [email protected]
}

But remember I use subdomains - each one set up in my host’s DNS to point at the public IP of my router and with only ports 443 and 80 open on my router, directed at the proxy.

I then have one blank line between this entry, and starting the next one.

I think yours should be:

domain.com
{
proxy /plex xxx.xxx.x.xxx:32400/web/ {
transparent 
websocket
}
tls [email protected]
}

domain.com
{
proxy /dsm xxx.xxx.x.xxx:5001 {
transparent 
websocket
}
tls [email protected]
}

domain.com
{
proxy /homeassistant xxx.xxx.x.xxx:5123 {
transparent 
websocket
}

… though you only need to add websocket if the thing you are proxying to uses websockets (HA does, not sure about the others).

As I use subdomains, however, I’m not sure if you need “domain.com” every time, though it seems like it should work so try the above I’ve provided and report back.

1 Like

I moved to subdomains and now it works!

The only thing that doesn’t work is to DSM synology. Maybe I will ask support on synology forum.

Thank you! :slight_smile:

Excellent! Glad I could help. DSM probably needs a setting set somewhere but I don’t use it.

Solved. The issue was related to redirecting http to https in DSM. Unflagging the option made it works!

:sunglasses:

This is really working wonderfull!! really simple to get it up and running!

1 Like

Hi Nikc,

how do you allow caddy to start at boot?

Step 3 on this guide: