Getting and setting request URL (path, query)

Hi, I need one small help with Caddy configuration.

  • explain what you are trying to do,
    I’m trying to use the params from the request URL and put it in the Caddyfile
  • show what you have already tried,
proxy /rest {$COM_SRV_2}{path}?{query} {
    header_downstream Access-Control-Allow-Origin "*"

The {$COM_SRV_2} is a valid env var on the server.

  • include error messages and log output,
Activating privacy features... done.
2019/04/26 15:29:54 parse http://{path}?{query}: invalid character "{" in host name

I have a Docker image that is running in the background that can be accessed (if running locally on localhost:5000/rest/cities?select=name) and it returns a JSON on the client side. In case you’re wondering, I’m using subZero. This Docker image is also up and running on my server.

NOTE: I’m using the Let’s Encrypt staging server while developing.

I have a registered domain at, and I’m trying to proxy the client for when the client navigates to he/she receives the JSON data from the server. If you navigate to you should see an error 404 message, that is good, it means that the Docker image for the API is running.

The thing I’m trying to accomplish is this.

So my question is, how do I write the Caddyfile properly, so that the URL params are passed into Caddyfile? I need the /rest/cities param and the ?select=name query, (which are location.pathname and in Google Chrome) and pass the strings in Caddyfile.

Howdy @VladimirDev93,

I don’t believe you can specify placeholders in a proxy’s upstream server.

Environmental variables passed into the Caddyfile are supported universally, because it’s a function of the Caddyfile loader, not an actual placeholder.

But http.proxy doesn’t parse placeholders in the upstream - the only thing it parses is a port range, I believe. So trying to use {path}?{query} is the issue here.

That said, the proxy should pass the entire path, query, and fragment along to the upstream server along with the request anyway - you shouldn’t need to append this information at all.

1 Like

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