How to specific a third port

Here is my config

server1 need run in port 80 and 443
server3 need run in port 80 and 443
server5 need run in port 9514 and 443

{
        http_port 80
        https_port 443
}

server1.com {
    reverse_proxy github.elmagnifico.tech {
        header_up Host {upstream_hostport}
        header_up X-Forwarded-Host {host}
    }
    handle_path /sg1 {
        reverse_proxy 127.0.0.1:55304
    }
}

server3.com {
    reverse_proxy 127.0.0.1:9514 {
      header_up Host {host}
      header_up X-Real-IP {remote}
      header_up X-Forwarded-For {remote}
      header_up X-Forwarded-Proto {scheme}
    }
    request_body {
      max_size 20MB
    }
}
server5.com:9514 {
    reverse_proxy 127.0.0.1:9515
}

Because some historical reason, i cant change the server5 port:9514. and server3 use the 9514 in local ,also cant change.

So caddy could recognize the in port? so that i could not differ the two , like my config. In fact my config is wrong , caddy cant set a server with port

How to specific a input port to a server ?

Please fill out the help topic template, as per the forum rules. We’re missing a lot of key information here to be able to accurately help you.

Remove all these. These are unnecessary, and typically break things. Let Caddy set these headers automatically. See the docs reverse_proxy (Caddyfile directive) — Caddy Documentation

You can remove header_up X-Forwarded-Host {host}, see the docs linked above.

I’m not sure I understand. Do you mean HTTP traffic on port 9514 and HTTPS traffic on port 443?

Are you actually serving that site over HTTP as well, or do you intend for it to be only HTTPS? If only HTTPS, why does it matter what the HTTP port is?

This implies to me that you already have another server on the same machine listening on port 9514. It’s impossible to have two programs listening on the same port, so Caddy would not be able to listen on that port unless your program is moved away from that port, or you run Caddy on a separate machine.

Thanks for you reply. I have knonw my issues.

Here is what i want to implement

server1 need run at   80(http) and 443(https)
server3 need run at 9514(http) and 443(https)
server5 need run at 9514(http) and no https

Due to historical reasons, they need to run on these ports(80,9514)and provide services

So caddy could listen two http port? and differ from different hostname?
Ignore my local port is which one, i was confused before you point my fault

Can will listen on whatever port you tell it to. But it won’t set up automatic HTTP->HTTPS redirects for you on anything but the default HTTP port.

I’m still not clear on what you’re trying to achieve here. Why do you need HTTP to be on a non-default port?

Because some link(with 9514 port) has been used in other server, i cant change them.And there may be a lot links use it by someone i don’t konw, i dont want to break their link.

Thank you ,I konw choosing 9514 non universal port is wrong

Then what I suggest you do is this:

http://server5.com:9514 {
	redir https://server.com{uri} 301
}

This would make sure requests using that old port would get redirected to HTTPS instead, using the standard port.

Thank you, i will try it

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