Forward all ports to one port on Caddy

Hello guys !

I’m going to start my caddy reverse proxy but have some issues , for example :

It works fine with one port “5000”
:80 {

  reverse_proxy localhost:5000

}

but whit below port doesn’t work for me (Port 5000 works but not 6000):

:80 {

  reverse_proxy localhost:5000
  reverse_proxy localhost:6000

}

I want to know how can forward all my ports ubuntu server to port 80 on caddy .

please help me how to do .

Thanks ,

Anybody to help me please

It isn’t clear what the criteria is for when to forward to :5000 or :6000.

Thanks for responsing

I want to start reversing proxy on port 1 to 1000 to forward on one port (80) .

For example exactly I’d like to connect to 80 and redirect to 900

How is it possible to request on port 80 and then connect to 900 ?
How can I do this on Caddy config ?

Thanks,

It’s not too clear what you’re asking for exactly. You already mentioned working config for a single upstream. For multiple upstreams, you will need to read up on request matchers and the reverse proxy directive.

It helps a lot more if you fill out the help template so we understand the context of your problem.

Thanks

I had run Open VPN from port 1 to 1000 .

So I have a Open VPN connection and made it on port 100 . I want to run reverse proxy to port 80 that I request on port 80 and connect to port 100 in my server .

Client has a open port on number 100 for Open VPN but I give number port 80 that my client to connect on port 100 with reverse proxy .

It sounds like you might not understand how Caddy is meant to work.

Caddy is an HTTP server and it has an HTTP reverse_proxy handler. It cannot proxy other types of traffic (with the vanilla distribution of Caddy, anyway – you could use caddy-l4 for arbitrary TCP/UDP proxying).

With your first config, you’re proxying incoming HTTP traffic on port 80, to another service you have running on port 5000. That’s fine.

With your second config, you set up two reverse_proxy directives. This cannot work as-is, because you didn’t tell Caddy which requests should go to which backend.

Handlers are a middleware chain. They run in a particular order, until something terminates the chain. The reverse_proxy handler is a terminating handler, so once it runs, nothing else does (there’s some caveats to that, but not relevant here).

You didn’t use a request matcher, so all requests go to the first terminating handler (which happens to be your proxy to port 5000).

It’s unclear to us what you actually want to do here. What do you have running at port 5000 and 6000? What kind of requests are you trying to send to one or the other? You can’t send them to both at the same time; a single request can’t be sent to two upstreams, because only a single response can be produced for a single request.

As @Mohammed90 said, please fill out the help topic template, as per the forum rules. It’s really not clear what your goals are, and filling that out will help us understand.

1 Like

This topic was automatically closed after 30 days. New replies are no longer allowed.