Let’s say I have a domain called mysite.com

mysite.com points to a server which only opens port 443, and each connection will need to go through that and deal with Caddy reverse proxy.

I want to host more services on it.

Let’s say I want to host an email service, the easiest thing would be using a subdomain such as mail.mysite.com and reverse proxy each connection to the internal port on which the service run.

Same with a chat service chat.mysite.com.

But for the sake of readability it would be much better to simply have username@mysite.com than username@mail.mysite.com or username@chat.mysite.com.

reverse proxying every request from a subdomain to the right port is pretty straightforward with Caddy, also if you use cloudflare you can proxy with cloudflare each subdomain and have auto SSL certificate without further set up, which is amazing!

But what if I do want my services to be accessed through mysite.com directly instead of a specific per-service subdomain?

Some federated services also have two separate ports for server requests and client requests, which further complicates the process…

Is this service specific and must configured individually for each service? Or there is a way to tell caddy that a specific request going through mysite.com should be redirected through port X.X.X.X? Is there a way Caddy can recognize where requests need to be directed?

  • BillibusMaximus@sh.itjust.works
    link
    fedilink
    arrow-up
    4
    ·
    3 days ago

    But for the sake of readability it would be much better to simply have username@mysite.com than username@mail.mysite.com

    That’s kind of unrelated. You can configure a mail server at mail.mysite.com to handle mail to/from username@mysite.com. You don’t need a proxy for that.

    But what if I do want my services to be accessed through mysite.com directly instead of a specific per-service subdomain?

    If they’re all http(s) services, then that should be possible. I don’t know anything about caddy, but with apache or nginx you can proxy based on path, so I’d assume you can with caddy also.

    For example mysite.com/chat could route to your chat app, mysite.com/webmail route to your webmail app, etc. But this isn’t necessarily plug-and-play, because depending on the app you might need to set up proxy rules for cookie rewriting, link rewriting, etc.

    If you want to proxy non-http(s) traffic from 1 port to multiple destination apps, then it gets a LOT more complicated.

    • CameronDev@programming.dev
      link
      fedilink
      arrow-up
      2
      ·
      3 days ago

      Doing the /service_name thing can get really messy if the web service has non-relative links. It gets very messy trying to do rewrite rules to fix that. Wouldnt recommend it.

  • ZWQbpkzl [none/use name]@hexbear.net
    link
    fedilink
    English
    arrow-up
    5
    ·
    3 days ago

    You don’t ssh in at ssh.mysite.com. Port 443 is form HTTPS traffic only. SMTP and IMAP traffic will require additional ports exposed that don’t need to go through caddy. Only the web UIs for your email will be exposed on the subdomains via caddy.

    Registering a mail domain is done through DNS records too not via caddy.

  • CameronDev@programming.dev
    link
    fedilink
    arrow-up
    2
    ·
    3 days ago

    So, you want to have two services accessible via the same URL? How do you want that to work? Can you give a list of services and the URLs you would like to access them by?

    At least for mail, its actually not too hard, because SMTP/POP etc are all on different ports, so you can host your mail at mysite.com, and still have a website at the same address.

  • SethranKada@lemmy.ca
    link
    fedilink
    English
    arrow-up
    1
    ·
    3 days ago

    It can be done, but only if the service your trying to use makes all of its requests using a specific port. There’s no way to do it with a reverse proxy to my knowledge though. I’ve got both my email and my blog at myname.tld, for example. I just had to configure both of them with DNS.

    If what your trying to do is have all requests for one port be directed to another port… your out of luck. I’ve been trying for ages to have nginx forward all 443 traffic on proxy.mynane.tld to 30018 and 80 traffic on proxy.myname.tld to 30024 but no luck so far.

    • BillibusMaximus@sh.itjust.works
      link
      fedilink
      arrow-up
      3
      ·
      3 days ago

      If you’ve been trying for a while and still haven’t gotten it working, then I’m probably missing something regarding your requirements.

      But at first glance, it seems like it would be solved with 2 server blocks, 1 for 80, 1 for 443, each with their own proxy config passing / to their respective target ports.