How to just let / path ONLY through the proxy

How to transform this nginx conf to Caddyfile

server {
    ...
    location = / {
        proxy_pass http://127.0.0.1:1041;
    }
    location / {
        root   /public;
    }
    ...
}

proxy doesn’t let you specify exact paths, only base paths, but there’s a few workarounds you could use. I can think of a few ways you could try to use rewrite logic to get what you want.

One option would be to:

  • Use placeholder logic to rewrite requests equal to / to another location such as /proxy
  • proxy from /proxy to your backend, and include a without /proxy subdirective to strip the extra basepath you’ve just rewritten to

Another way:

  • Use placeholder logic to rewrite requests NOT equal to / to another location
  • Create another vhost for that location (Caddy will always use the most specific host block)
  • In the main host block, proxy everything from / to your backend
1 Like

Thank you.

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