Proxy, forward internal requests

Hi guys.

I have been trying out Caddy for a week and I would like to know if forwarding internal requests is possible.

I use a proxy like this :

192.168.100.26:2015 {
log stdout
  errors stdout 
  
  bind {$ADDRESS}
  
  proxy /minich 192.168.100.82:9000 {
    transparent
    without /minich
  }

  tls self_signed
  
}

The redirection works fine when I go to ip/minich I got what I want except for a few things : all the internal requests, for example /app/thumbs.png are not redirected too. It should be forwarded too to /minich/app/thumbs.png but they aren’t…

I have tried using the redir and rewrite directive with redir /minich /app 307 but I got an url such as /minich/minich/minich/…/app

Is there a way to do this in Caddy or is it server-side ?

Regards,
Alexi

Looks like you want to proxy all requests instead. Why not get rid of the /minich path ?

Can you list some request paths and expected proxy path maybe I can better understand what you are trying to achieve. e.g. /minich -> /

Thanks for the answer abiosoft, keeping /minich in the path is not mandatory.

The only thing I want is to have all the ressources
I have tried with the caddyfile I gave on the topic and I got this error

The request should be /minich/account/login but I don’t know how to proxy my http requests in Caddy (or if this is even possible)

Given your directive, where should I put this line ?

Looks like all you need is this

192.168.100.26:2015 {
log stdout
  errors stdout 

  bind {$ADDRESS}

  proxy /192.168.100.82:9000 {
    transparent
  }

  tls self_signed
  
}

That doesn’t answer my question :frowning:

I want to keep the proxy to /minich, I only want that internal requests such as the one I gave you are also forwarded (using rewrite or whatever)

For example a request wich normally goes to /app/thumbs.png to be automatically forwarded to /minich/app/thumbs.png using caddy

That is why I asked you to give some examples of request path and expected proxy path so I can fully get what you are trying to do.

E.g. the following requests should be proxied to what path upstream ?

/minich -> /
/app    -> ?
/other  -> ?

The following path should be proxied like this

/minich -> /192.168.100.82:9000 (as the proxy does I guess)
/app -> /minich/app
/other -> /minich/others

The /minich proxy is working, but then the others path (links etc) are not proxied

Try this

192.168.100.26:2015 {
  log stdout
  errors stdout 

  bind {$ADDRESS}

  rewrite {
    if {path} not_match ^\/minich #does not start with /minich
    to /minich/{uri}
  }

  proxy /minich 192.168.100.82:9000 {
    transparent
    without /minich
  }

  tls self_signed
  
}

It works thanks abiosoft !
Best regards

1 Like

Just forgot to ask one thing, what if I want several rewrites ?
Using this CaddyFile :

192.168.100.26:2015 {

log stdout
errors stdout

bind {$ADDRESS}

rewrite {
if {path} not_match ^/minich #does not start with /minich
to /minich/{uri}
}

proxy /minich 192.168.92:9000 {
transparent
without /minich
}

proxy /something 192.168.100.82:9000 {
transparent
without /something
}

tls self_signed
}

Can I have the same thing working for both ?

You should be able to add another rewrite block without issues. Can you elaborate on what you mean by several rewrites ?

Thanks for the reply.

For example, let’s imagine I have one URL per user, I have one client called minich and one called something, each one of these should be redirected to it’s own app.

I would like that each request is forwarded to other path without overwritting the ones from the other clients (which the previous answer does)

For example

/minich/{uri}
/something/{uri}

I cannot write a rewrite inside a proxy, and the user number is not supposed to be at only 2. SO is there an easy way to do this or do I need a regular expression for all the cases ?

How do we differentiate requests from different users. Does that mean requests meant for minich goes to /minich/... and something goes to /something/... respectively ?

Well I don’t really know, for the moment it is not implemented but is there a way to do this when I declare a new proxy directive ? like this

proxy /minich oneIP {
# rewrites here when you are in minich
}

proxy /something secondIP {

rewrites here when you are in something

}

Where all the links for a user are the same (they use a different instance of the app)

Yeah, that works.

But we can’t rewrites inside of a proxy directive, so I think I will have to use an other solution, thanks for the help

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