Reverse proxy doesn't work

Hi there,

I’m new to Caddy, just tried and can’t get the basic reverse proxy work with this setting, anything wrong? {
    proxy /api/ some-lan-server:2017
    proxy /home/ localhost:2017

But this actually works to me: {
    proxy / some-lan-server:2017

Any clue? thanks a lot

Well, there’re too many circumstances in this regard,
Below, is my working configurations as I already use caddy as master proxy providing access to anything i may choose from anywhere i.e. outside LAN considering NAT forwarding and firewalls settings are routed correctly. {
proxy / { transparent insecure_skip_verify }

In the above example, caddy is listening to port 443 on the machine facing WAN so that all requests to will be directed to another machine at which the service - say chat - is listening to port 5443.

Hmm, maybe remove the trailing slashes and see if that makes a difference?

    proxy /api some-lan-server:2017
    proxy /home localhost:2017

Thanks for the reply. Actually I tried a lot different ways, with or without trailing slashes, etc., I suspect there might be some stupid mistake with my URL, for example, it works to access the original URL:


But with the proxy, I got a 404 error:


Is that a mis-usage?

Thanks a lot

Ahh, I think I see what your issue is!

By default, Caddy proxies whatever matches the basepath (in your case /api) to the upstream, preserving the entire URI (including /api).

So your endpoint works when you query http://some-lan-server:2017/some/path, but Caddy is actually requesting http://some-lan-server:2017/api/some/path.

To fix this, you’ll want to use the without subdirective, to strip the /api prefix from the request before sending it upstream.

	proxy /api some-lan-server:2017 {
		without /api

Thank you! It works :grinning:

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