Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proxy different paths on the same domain to different ports #39

Open
jochemkeller opened this issue Oct 16, 2024 · 2 comments
Open

Proxy different paths on the same domain to different ports #39

jochemkeller opened this issue Oct 16, 2024 · 2 comments
Assignees
Labels
feature feature request needs-more-info needs more information from the reporter server related to the server / core logic

Comments

@jochemkeller
Copy link

jochemkeller commented Oct 16, 2024

Hi Peter,

First of all thanks again for a great tool! As mentioned before it's become essential to my workflow 🙏
Now than, a feature request, or maybe question, of sorts.

I've ran into a situation where I'd like to have a main domain linked to a port, but then have a unique sub-directory assigned to a different port. In terms of localias config, something like:

# localias config file syntax

domain.local: 3000
domain.local/subdirectory: 3001

Right now, this gives the following error:

error: loading new config: loading http app module: provision http: server srv0: setting up route handlers: route 0: loading handler modules: position 0: loading module 'map': http.handlers.map: invalid configuration: mapping 1 has a duplicate input 'domain.local' previously used with mapping 0

which is understandable, but could this potentially work? Or do you see any blockers?

Thanks beforehand for taking the time to review this issue!

@peterldowns
Copy link
Owner

peterldowns commented Oct 16, 2024

Hey Jochem, nice to hear from you — glad to hear that you're still using and benefiting from Localias :)

Something like this is certainly possible. Caddy, which handles all the reverse proxying, supports proxying based on route matching. For the example you gave, I think the generated Caddy config would need to look something like:

domain.local {
  handle /subdirectory/* {
    reverse_proxy :3001
  }
  handle {
    reverse_proxy :3000
  }

  tls {
    issuer internal {
      ca local
      # allow on_demand issuing, but doesn't turn it on
      on_demand
    }
    # turn on on_demand issuing to automatically renew certs
    # when they expire
    on_demand
  }
}

Right now, the generated configs look like this:

domain.local {
  reverse_proxy :3000

  tls {
    issuer internal {
      ca local
      # allow on_demand issuing, but doesn't turn it on
      on_demand
    }
    # turn on on_demand issuing to automatically renew certs
    # when they expire
    on_demand
  }
}

I'll think about how to extend localias with this capability — I could benefit from it myself. I think the only tricky bits will be managing the routing logic and making sure that any errors or problems are understandable and debuggable for users.

Once the door is opened to path-based routing, I could also see people asking for more features that Caddy offers. At the limit, Localias could offer the ability to write a full Caddyfile! I don't want to go all the way down that road, but I'm willing to look at a few possible features that we could expose.

In summary, I'm open to adding this directory-based proxying capability. I'm curious to know if anyone else is interested in this feature or in any other advanced Caddy routing/matching capabilities. I'll leave this issue open until there's a clear path forward. Thank you for the question/suggestion/request.

@peterldowns peterldowns self-assigned this Oct 16, 2024
@peterldowns peterldowns added needs-more-info needs more information from the reporter feature feature request server related to the server / core logic labels Oct 16, 2024
@peterldowns peterldowns changed the title Allow unique sub-directories Proxy different paths on the same domain to different ports Oct 16, 2024
@jochemkeller
Copy link
Author

Hi Peter,

Awesome! Thanks for considering the feature request & the thorough response.
Indeed, one of the things I really like about the .localias.yaml configuration file is that it's essentially an abstraction layer that takes away a lot of the complexity of Caddyfile config. This allows colleagues who don't have a lot of experience in that field to still achieve complex stuff 👍

If you require any further information on how I / we would use this at an enterprise-type scenario, please let me know, I'd be happy to provide more details :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature feature request needs-more-info needs more information from the reporter server related to the server / core logic
Projects
None yet
Development

No branches or pull requests

2 participants