Reverse-proxying sub-path to Golang webserver (v2)

Hello,
I’ve been trying to re-create my NGINX production environment with Caddy for local development. I have an NGINX proxy that proxies Home - Ownwebsite to 192.143.231.42:8080, e.g. Home - Ownwebsite would proxy to 192.143.231.42:8080/index, I would like to replicate that with Caddy…
So far I have this Caddyfile:

:1234
reverse_proxy /motorhead/  {
	to 0.0.0.0:8081
}

But it gives me a 404 whenever I try to access the /motorhead/ uri even though 0.0.0.0:8081/ works fine and returns the correct HTML page. Reverse-proxying to / works but breaks all of my production HREFs…

Thank you for reading!

I think this thread should help you

https://caddy.community/t/v2-rewrite-proxy/6555

1 Like

Ah yes, working on this problem today in fact.

I tried:

rewrite /motorhead/ /

and:

rewrite /motorhead/ /
reverse_proxy / 0.0.0.0:8081

But without any success sadly… I guess if @matt is working on it then I’ll just be patient and work on something else in the meantime, please do let me know when a fix goes live! Finally, let me know if there’s anything I can help with.

Just a heads up - this is a limitation of the Caddyfile (currently, and probably not for much longer), but you should still be quite capable of configuring this if you are willing to go to JSON configuration directly, which will give you much more control.

1 Like

And here’s how to kick-start your JSON from your Caddyfile: Command Line — Caddy Documentation

Does the json parser to any ENV variable replacement?

Substituting env variables is not done at the JSON parsing level. Placeholders are evaluated during module provisioning. Most Caddy modules honor placeholders where you would want them: Conventions — Caddy Documentation

If you find a field that doesn’t support placeholders that should, please let me know or submit a separate PR! :slight_smile:

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