How to serve a reverse proxy as a path on an existing domain like example.com/api?

1. My Caddy version (caddy -version):

Caddy v1.0.4 (h1:wwuGSkUHo6RZ3oMpeTt7J09WBB87X5o+IZN4dKehcQE=)

2. How I run Caddy:

As of now bare cmd run

caddy.exe --conf Caddyfile

a. System environment:

Windows 8

d. My complete Caddyfile:

As of now it is

localhost:80
root PATH_TO_MY_INDEX file

proxy /api localhost:8081

3. The problem I’m having:

From the internet the application will be server on example.com and I want to allow the Vue application to make API calls to example.com/api while the API is actually served at localhost:8081

The real question, after how to accomplish this is to preserve the requested uri, as example.com/api/myresource should be mapped to localhost:8081/myresource bringing with it all the path and query parameters

5. What I already tried:

I am fiddling with proxy and rewrite mods without wrapping my head around how to accomplish this

Hi @Maxiride,

Have you tried something like this?

example.com {
  root /path/to/index.html
  proxy /api localhost:8081 {
    without /api
  }
}

without is a URL prefix to trim before proxying the request upstream. A request to /api/foo without /api, for example, will result in a proxy request to /foo.
https://caddyserver.com/v1/docs/proxy

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