Caddy proxy app (newbie question)

Hi,

I’m very confused to use proxy with Caddy

Simple example :

  • 1 web application with HTTP Server (Flask, Gitlab, …), port 80 (on docker)
  • 1 Caddy for proxy, port 80 and 443 (on docker)

New user cannot post with more than 4 links, so add http or https before // (:()

Application don’t have parameter like base_url, so each page and ressources point on address (//myapp/index.html, //myapp/css/mycss.css, //myapp/js/myjs.js, …)

Caddy proxy request to application with this configuration :

//caddy
{
  tls self_signed
}

//caddy/app
{

  tls self_signed
  proxy / //myapp {
    transparent
  }
}

If i go to //caddy/app, proxy done and get //myapp/index.html but all ressources is missed (they try to //caddy/css/mycss.css and not //caddy/app/css/mycss.css

How can do this simply ? I try rewrite and filter with no success (perhaps i don’t use this directives correctly).

Thanks !

Hi @PaulSka,

Regarding the links - code-formatted links aren’t counted (because they aren’t hyperlinked), so you can put your examples in code blocks.

What’s happening is that you’re proxying everything after /app directly to the webroot of your destination. You want to ensure that /app remains appended to the destination, so try this instead:

caddy.example/app {
  tls self_signed
  proxy / http://myapp.example/app {
    transparent
  }
}

Hi @Whitestrake

I have 0 control on proxying app.

I try to make more cleaner.

This is (awesome) scheme

awesome_schema

And my Caddy File

https://localhost/
{
  tls self_signed
  ...
}

https://localhost/app1,
{
  tls self_signed
  proxy / http://app1 {
    transparent
  }
}

https://localhost/app2,
{
  tls self_signed
  proxy / http://app2 {
    transparent
  }
}

https://localhost/app3,
{
  tls self_signed
  proxy / http://app3 {
    transparent
  }
}

If i go to https://localhost/app1, i see my page but, all dependencies (Js, CSS) are missing. They try to load https://localhost/css/my.css (they not exists). If i point to https://localhost/app1/css/my.css it’s fine.

I try your code but they redirect to http://myapp.example/app (they don’t exists)

You generally can’t put an app in a subfolder unless it expects to be inside a subfolder. The app itself is generating those links - you need some way to tell the app to generate the correct ones.

This almost always involves sending the full path including subfolder upstream. Having the URI aligned between reverse proxy and upstream server is a much simpler configuration. By proxying from a subfolder to the web root upstream, you’re stripping the subfolder prefix - the client sees /app1/foo/bar but the app itself thinks someone’s requesting /foo/bar.

Otherwise, if you know the format that those links take in HTML, you could try using http.filter to have Caddy rewrite them before sending them back to the client.

https://caddyserver.com/docs/http.filter

Ok thanks you @Whitestrake

I use http.filter, it’s more confortable for me

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