Closed JosiahParry closed 2 weeks ago
@JosiahParry Maybe try pingap? It is built on a pingora. https://github.com/vicanso/pingap
No, that's not what I'm after. I'd like to define services and have pingora spin them up and down as needed as illustrated by the user guide.
But before I can do that I'd like to take baby steps to get there. The first of which would be showing that I can proxy to a local service
@JosiahParry ~Not sure you can just append the LB there~ nvm, you can -- you just missing the impl HttpProxy
for it.
Make sure you are following this guide: https://github.com/cloudflare/pingora/blob/main/docs/quick_start.md#create-a-pingora-server
TL;DR: afaik you are missing the impl HttpProxy
that allows you to select a backend
Thanks @luizfonseca! This is exactly the quickstart except changing the upstream
to instead be a local service served at 127.0.0.1:9000
which is why i'm a bit confused why its not working. Using the one-one-one example works. But using a local address does not work
@JosiahParry Ah, gotcha!
This line here in your impl HttpProxy
:
let peer = Box::new(HttpPeer::new(upstream, true, "one.one.one.one".to_string()));
The true
there is configuring this backend connection to use tls -- but since you are running against a local/non-ssl service you can change that to false
.
let peer = Box::new(HttpPeer::new(upstream, false, "one.one.one.one".to_string()));
(you can also just issue your own certs locally and use https:// in your :9000
service to keep the true
there, but that's another config step)
EDIT: it works in the example because it is targetting cloudflare's 1.1.1.1
(which uses tls)
@luizfonseca thank you! That worked. Simple enough :) I'll close the issue.
For my continued exploration, I'd like to spawn services automatically.
I have a struct that spawns a service at a random port that I'd like to proxy to. Do you know which part of the docs / examples should I explore to have pingora spawn/close/manage the service and proxy to it?
Thank you so much that has been a huge help!
@JosiahParry Interesting, it might be that documentation is sparse in that case, but:
What you can explore:
pingora
is mostly a struct that has impl Service
(see an example from a reverse-proxy I'm building atm ) that is then added via server.add_service
HttpProxy
struct: crate: pingora-proxy that then runs all the required impl ProxyHttp
trait functionsserver.add_service
(maybe a mpsc?) and then gracefully restart when things change.The other point I wanted to make is that you could also just group everything in 1 listener with multiple (worker) threads that has access to some sort of routing state (dashmap, arcswap etc) for better connection reuse, but that's only useful if it fits your use case anyway.
EDIT: Some other points you can look at:
I'm working with Caddy right now but I'd like to move to a rust based solution that allows me to spawn new services as i need. I think pingora is the solution but am having a lot of trouble getting a minimal example running.
I'm trying to adapt the quickstart reverse proxy to work with a local service but am having no luck.
For example i have a local app running at
127.0.0.1:9000
I've modified the
LoadBalancer
so that it only calls the local service.However, when I run this I get a 502 in the browser and there is no messaging being printed to stdout as to why this might be.
Are there any examples that illustrate proxying to a local service?
Ideally, I'd have a struct that can represent the app / service that can spawn new instances based on demand on random ports by, I think, implementing the
Service
trait. but before that, i'd need to prove that pingora can even proxy to a local app.