How to make reverse_proxy work properly

1. Caddy version (caddy version):

v2.3.0

2. How I run Caddy:

I have some servers, and my IP port 80 and 443 is blocked. I use NAT to serve online, But it comes out lots of NAT rules. So I created a web that contain all the services, and make just one NAT rule for this web, all services are reverse proxyed.
Services list below:
EMBY: 192.168.1.200:8096
Resilio: 192.168.1.170:8888
PVE: 192.168.1.175:8006
Calibre: 192.168.1.200:8080
Transmission: 192.168.1.20:9091

My Web with Caddy2 : 192.168.1.10

a. System environment:

Ubuntu 16.04.5 LTS

b. Command:

paste command here

c. Service/unit/compose file:

paste full file contents here

d. My complete Caddyfile or JSON config:

:80
root * /usr/share/caddy
file_server
handle_path /emby/* {
reverse_proxy 192.168.1.200:8096
}

handle_path /book/* {
reverse_proxy https://192.168.1.200:8080
}

handle_path /tr/* {
reverse_proxy 192.168.1.20:9091
}

handle_path /sync/* {
reverse_proxy 192.168.1.170:8888
}

handle_path /pve/* {
reverse_proxy https://192.168.1.175:8006
}

3. The problem I’m having:

1). Only EMBY works, 192.168.1.10/emby/
2). Resilio Transmission Not work, only blank page, and the url transformed with no handle_path. like 192.168.1.10/web or 192.168.1.10/transmission. not 192.168.1.10/sync/ or 192.168.1.10/tr/
3). Calibre shows :
Failed to communicate with “/book/interface-data/init?1610587317779”, with status: [400 (error)] Bad Request
The uri in the Request Line and the Authorization header do not match
4). PVE show nothing but blank page
5). all url must contain “/” like 192.168.1.10/emby/, 192.168.1.10/emby not work.

I want any service works fine, and “/” is not necessary.

4. Error messages and/or full log output:

5. What I already tried:

6. Links to relevant resources:

Just change handle_path /emby/* to handle_path /emby* then.

For the rest, this is likely your problem:

I recommend using subdomains instead of subpaths to proxy services whenever possible.

Make sure to look at Caddy’s logs to see what’s going on, Caddy may not be connecting to your proxied services correctly.

1 Like

I do want to use subdomains, only if my server conect to the web directly.
The situation is that my caddy server is just behind my router which cannot run caddy to capture subdomains, the router only can NAT the web request, so I had to use subpaths, if you have any good advice to solve this situation, PLS DO Help me

My recommendation is to run a DNS server in your home network. CoreDNS does the job nicely for this.

Your Corefile would look something like this:

. {
    hosts {
        <caddy-server's-ip> <one-or-more-domains...>
        fallthrough
    }
    forward . 8.8.8.8
}

You can configure your router to use your server with CoreDNS installed as its DNS, and the rest of the devices on your network will inherit it.

This way, while inside your home network, the domain will resolve to the LAN IP, while outside of your network, it’ll resolve to your WAN IP.

1 Like

I’ll try, Thank you

1 Like

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