Create a reverse proxy for two ports

I apologize about the typo. I fixed that, and now when routing to domain/server/, it seems to work a lot better.

However, I am still having issues with the ui route. When I go to http:ip:5000, i get what id expect. When I go to domain/ui, I see: manifest.json:1 Manifest: Line: 1, column: 1, Syntax error. The app running on port 5000 is a docker container running a React Application (with react router). If you think this is causing the issue, or I should be using file-server for that, let me know.

I am also having an issue that if there is every a redirect called on the /server route, it goes back to the / route. So if I have domain/server/route1 that will conclude by redirecting to /route2, it will just redirect to domain/route2. I tried writing in the caddyfile just handle /server (bc of the stuff you mentioned with stripping the prefix), which was not helpful. I tried as a desperate attempt to do redir / /server/, which didn’t solve the issue either.

To clarify my goal, I have one application, the server, running on 8080, and I have the ui running on 5000. I want both of these applications to be under one subdomain.

updated caddy file:

domain

redir /server /server/
handle_path /server/* {
    reverse_proxy ip:8080
}

redir /ui /ui/
handle_path /ui/* {
    reverse_proxy ip:5000
}

I also wanted to say that I am shocked at how fantastic the support has been on this community. I left a question last night with the assumption I’d check it the next day and maybe have an answer. I cannot believe I already have a thread 20 messages long (sorry for my long delay, I’ve gotten maxed out at how many replies a new user can have on their first day :slight_smile: ). Thanks so much!

1 Like

At this point I think you need to update some configuration on your upstream server such that it understands it’s meant to run in a subpath.

Please read this wiki written by @Whitestrake, I think it will illustrate the issues you’re having.

i have the same problem,V2: how can caddyfile reverse_proxy to JSON

i want to proxy filebrowser, in caddyfile of caddy1,the config:
in caddy1, i can do it:

127.0.0.1:2016 {
proxy /filebrowser 127.0.0.1:8080
}
it works well,
but i want to use filebrowser in caddy2
in caddy2 json config file,
{
“handler”: “reverse_proxy”,
“transport”: {
“protocol”: “http”,
“read_buffer_size”: 4096
},
“upstreams”: [
{
“dial”: “127.0.0.1:8080”
}
]
}
proxy / to 127.0.0.1:8080. it work well
but i want to proxy /filebrowser to 127.0.0.1:8080
i search all Internet, but do not find the example of json file
i get a response,
“The easiest thing to do if when learning to write JSON configs with Caddy is to write what you want as a v2 Caddyfile then adapt it to JSON with the caddy adapt command.
In Caddy v2, it would look like either of these, depending on whether your upstream service expects the subpath to be stripped or not.

in caddyfile:
handle /filebrowser {
reverse_proxy 127.0.0.1:8080
}
“
i use 'caddy adapt ’ to json, and copy to .json file
but it dont work

@Schr0dingerCat in Caddy v2, path matching is exact-match. This means that your matcher /filebrowser only matches exactly /filebrowser and nothing else. You need to append a * to tell Caddy that you want to match anything that begins with /filebrowser.

This is probably all you need:

127.0.0.1:2016 {
	reverse_proxy /filebrowser* 127.0.0.1:8080
}

Also, please don’t forget to use ``` on the lines before and after your config/code to use code block formatting (preserves whitespace, uses a monospaced font) next time you comment on the forums, it’s hard to read your post when it doesn’t use proper formatting.

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