Proxy with rewrite

(Great Fire Wall) #1

I want to rewrite all other not proxy path.

But I get Error during parsing: Wrong argument count or unexpected line ending after '/mysql'

How can I do ?

Note a and b is docker service, I’m using caddy in docker., {
    header / Strict-Transport-Security "max-age=31536000;"
    proxy /api a:5000 {
    proxy /mysql b:8080 {
    rewrite {
        if {path} not /api and {path} not /mysql
        to {path} /
(Matthew Fay) #2

Hi @GreatFireWall, welcome to the Caddy community.

You can’t use a full chain of logic on a single if subdirective. The syntax is if a cond b, each instance must take three arguments.

Instead, specify multiple if subdirectives.

  • if specifies a rewrite condition. Multiple ifs are AND-ed together. a and b are any string and may use request placeholders. cond is the condition, with possible values explained below.
  • if_op specifies how the ifs are evaluated; the default is and .

(Great Fire Wall) #3

Thanks your guide.
And can you show me an example how to use if_op if it’s or ?

(Matthew Fay) #4

The syntax is if_op [and|or].

The rest is the same - use multiple if subdirectives. With if_op or set, the rewrite can be executed if any of the conditionals match, instead of all of the conditionals having to match.

(Great Fire Wall) #5
rewrite {
    if {path} not /api 
    if {path} not /mysql
    to {path} /

Is this right ?

(Matthew Fay) #6

I’m afraid not. and is not a subdirective of rewrite. The rest looks good.

The only subdirectives you can use are regexp, ext, if, if_op, and to. Give the docs another read, specifically the syntax section:

You don’t specify between each if statement whether they’re grouped AND or OR. You simply specify all the conditions, then you can optionally specify how all of them are grouped.