Skip to content

Instantly share code, notes, and snippets.

@wilmoore
Created December 2, 2024 20:52
Show Gist options
  • Select an option

  • Save wilmoore/a7c47269cb17bf76cff2b927d67e37ae to your computer and use it in GitHub Desktop.

Select an option

Save wilmoore/a7c47269cb17bf76cff2b927d67e37ae to your computer and use it in GitHub Desktop.
Software Engineering :: Web :: Development :: HTTP :: Server :: Caddy :: Configuration :: Caddyfile :: Example :: Reverse proxy

Software Engineering :: Web :: Development :: HTTP :: Server :: Caddy :: Configuration :: Caddyfile :: Example :: Reverse proxy

⪼ Made with 💜 by Polyglot.

Proxy all requests
example.com {
	reverse_proxy localhost:5000
}
Only proxy requests having a path starting with /api/ and serve static files for everything else

This uses a request matcher to match only requests that start with /api/ and proxy them to the backend. All other requests will be served from the site root with the static file server. This also depends on the fact that reverse_proxy is higher on the directive order than file_server.

example.com {
	root * /var/www
	reverse_proxy /api/* localhost:5000
	file_server
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment