Hello, all. I’ll start this post off with - this is a test. :P I have the same topic posted at /r/… seeing if I get any l<3ve over here!!! I hope so!!! LemmyNet for the WiN!

I have two domains that I pay for… lets call them domain1.com and domain2.com. I’m running a Bitwarden docker container that uses nginx to serve the website… its address is bitwarden.domain1.com .

I’m running a HUGO website with Apache2… its address is domain2.com .

I have one local IP address; currently, I forward ports 80 & 443 to the local IP of the Bitwarden VM. So… thats my issue; I don’t understand how to forward these two different services to the domains that I want them on… I’ve read about Apache2’s vhosts - but the websites are on different VMs, and the Bitwarden docker container uses nginx.

I’ve thought about condensing and putting both services in one VM; but theres still the apache2/nginx issue. I’ve heard someone mention I should use a third VM to route the traffic to the correct local IPs - but I don’t know what software I’d use.

I’ve thought about using a Cloudflare tunnel for one of those services; but I don’t really want to pay, and aren’t sure how fast a free Cloudflare tunnel would be - this might be a solution for the Bitwarden service, as I’m the only one accessing it…

Does anyone have any suggestions? I’m sure I’m just novice enough that I don’t see the obvious solution - and I’d love to get both sites up and running. Thanks for any input or help!!!

pAULIE42o . . . . . . . . . . . /s

  • paperemail@links.rocks
    link
    fedilink
    arrow-up
    2
    ·
    edit-2
    1 year ago

    Please correct me if I’m wrong, but here’s what I think the situation is:

    • you have two different sevices that you have domains for, e.g. lemmy and bitwarden.
    • you have two domains, lets call them lemmy.com and bitwarden.com .
    • you have one (public?) IP address. let’s call that 123.123.123.123 .
    • you want to use this IP address for both domains (e.g. bitwarden.alpha.com and lemmy.beta.com)

    In that case you need both domains to connect to the same computer (because that’s the one with that IP address) which routes it to the correct location (either on the same computer or on a different one).

    You basically have two solutions (that you already mentioned)

    1. single machine

    • You run both services on a single machine, listening on different ports on localhost/127.0.0.1 .
      • lemmy listens on port 1234 and bitwarden on port 8080.
    • You use nginx (or caddy/apache) to listen on the web ports (80, 443) and reverse proxy(!) the content.
      • if the domain is lemmy.com it proxies from localhost:1234
      • if the domain is bitwarden.com it proxies from localhost:8080 This is the easiest solution IMO.

    2. different machines.

    This is essentially the same, but instead of the services running locally, one or both run on different machines.

    • you run both services on different machines
      • lemmy on 10.0.0.10:1234
      • bitwarden on 10.0.0.20:8080
    • You use nginx again as reverse-proxy(!):
      • if the domain is lemmy.com it proxies from 10.0.0.10:1234
      • if the domain is bitwarden.com it proxies from 10.0.0.20:8080
    • be sure to check the firewall settings of the machines, that allow it.

    In both cases the IP address points to the machine running nginx.

    If you can run both services on the same machine with docker, you should just use this: https://github.com/nginx-proxy/nginx-proxy

    • pAULIE42o@beehaw.orgOP
      link
      fedilink
      arrow-up
      1
      ·
      1 year ago

      Thanks so much for the reply; others have mentioned the same, or similar, but your response spelled it out… I knew this was what I needed to do [scenerio 2] but I just didn’t have experience with setting up the proxy - I’m technical enough to RTFM and will get this setup today; one thing that was kinda fudging me up was that my Bitwarden machine, where the domain currenty forwards to, runs in a docker container - so I think I’ll actually forward the OTHER domain to the ‘lemmy’ [although its not lemmy, just using your example as the reference…] machine that’s just an Ubuntu server running apache2 for serving the website - and I’ll probably end up using Apache’s Name Based Virtual Host Support instead of your nginx-proxy suggestion - either way, I think its accomplishing the same.

      Appreciate your, and all the other, replies - this thread literally performed better than on the /r/ platform! I’m sold on LemmyNet!

      • paperemail@links.rocks
        link
        fedilink
        arrow-up
        1
        ·
        1 year ago

        Both nginx and apache are webservers and can do what you need.
        Apache calls this Name-based Virtual Hosts. (see ServerName/ServerAlias)
        Nginx calls this Name-based virtual servers (see server_name in the docs)

        Either will listen on ports 80/443 on the IP and proxy the request depending on the hostname used. If you’re not really familiar with either, I would recommend nginx. It’s very popular, the documentation is good and the syntax is a lot better IMO.

        I hear caddy is also a nice alternative with even simpler syntax, but I haven’t used it myself.

        Good luck!

      • paperemail@links.rocks
        link
        fedilink
        arrow-up
        0
        ·
        1 year ago

        I can see how you’re not yet familiar with all these terms :p Both nginx and apache are http servers and work the exact same in your case.

        The server (apache or nginx) listens on the IP on port 80 and 443. Depending on the hostname that is used to connect, the request is proxied to a different location. Apache calls this virtual hosts, nginx call this virtual servers

  • pAULIE42o@beehaw.orgOP
    link
    fedilink
    arrow-up
    2
    ·
    1 year ago

    LOL… it’ll be easy, I tell ya!

    So I dove in this afternoon, thinking I had all the info I needed to easily get a setup w0rking… I changed my port forwards to the domain2.com machine - the one running apache2 on a webiste; leaving the bitwarden.domain1.com not seeing traffic. Then, I created a new virtual host file on the domain2.com machine;

    cat bitwarden.domain1.com.conf

    <VirtualHost *:80>

        ServerName bitwarden.domain1.com
    
        ProxyPass / http://10.0.0.155/ nocanon
    
        ProxyPassReverse / http://10.0.0.155/
    
        ServerAdmin paulie420@domain1.com
    
    ErrorLog ${APACHE_LOG_DIR}/error.log
    
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    

    RewriteEngine on

    RewriteCond %{SERVER_NAME} =bitwarden.domain1.com

    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

    </VirtualHost>

    And ran certbot to get https certs - certification would only be on the domain2.com machine; all proxied data would be sent over http, but I figured that was OK as its just me accessing the domain1.com service.

    BUT alas, the setup didn’t work; I have some suspicions… bitwarden is running inside a docker container, so… I dunno if that has something to do with how its listening, and its running nginx; what I thought was that apache2 would simply send all traffic from the bitwarden.domain1.com domain over to my local IP 10.0.0.155 machine and that machine would just pick it up simple pimple and display to the user going to that domain. Another thought - maybe its because Docker/Bitwarden HAS https in that container - ohhhh, thats a thought; however it still didn’t function correctly before I ran certbot on the domain2.com setup.

    UGH… more to come - I’m trying options. :/ Grrrrrr. :P

    PS; posting code in Lemmy doesn’t work so great, does it? I used a backtick but didn’t get the results I’m accustomed to…

    • alyaza [they/she]@beehaw.orgM
      link
      fedilink
      English
      arrow-up
      3
      ·
      1 year ago

      PS; posting code in Lemmy doesn’t work so great, does it? I used a backtick but didn’t get the results I’m accustomed to…

      it might be because lemmy uses commonmark instead of regular markdown, so the formatting is slightly different from… most markdown things, i guess?

  • Mallias@lemmy.ml
    link
    fedilink
    arrow-up
    2
    ·
    1 year ago

    I found Nginx Proxy Manager to be the easiest to configure when I was starting out my homelab! I think the GUI played a big part in that, but it’s also just pure NGINX under the hood, so when you get more comfortable with the concepts, you could easily transition to that for even lower overhead (welp, I just had a look at my docker stats, NPM is sitting at 3.2 MB of ram with ~10 proxy hosts, not sure how necessary that even is…)

    • 0spkl@kbin.social
      link
      fedilink
      arrow-up
      0
      ·
      1 year ago

      If you’re going to be jumping straight into text based config files… Caddy’s Caddyfile format is a lot easier to work with then nginx configs IMO.

      • Mallias@lemmy.ml
        link
        fedilink
        arrow-up
        0
        ·
        1 year ago

        Well, I’ve been self hosting for a few years now, haven’t really had the need to jump into a text config for NGINX yet (apart from the rare custom configs some services need, but those are still done in the GUI). Caddy has it’s draws, as does traefik, but I think it’s easier to learn the concepts with the ease of use a GUI offers!

        • pAULIE42o@beehaw.orgOP
          link
          fedilink
          arrow-up
          1
          ·
          1 year ago

          I live mostly on the command line - I’m not afraid to edit .conf files by hand and its how I do most all things - maybe that’s why I’m having trouble with this setup!! LOLZ

  • pAULIE42o@beehaw.orgOP
    link
    fedilink
    arrow-up
    1
    ·
    1 year ago

    Alright, I wanted to come back now that my setup is complete… special thanks to those of you who suggested nginx-proxy-manager - its very nicely put together and really makes reverse proxies a breeze…

    Long story short, I just created a brand new VM… started with the proxy manager and built on top of that. Next up was my static Hugo website; it was too easy to point change Apache2’s ports.conf to 8097 instead of 80, and use nginx-proxy-manager for the SSL certs… that one was basically plug and play.

    The Bitwarden bit was a bit more involved, but not too bad… at first I just redirected traffic to the original (other machine) Bitwarden VM - but no one wants an extra VM to backup and support… so I went with a fork Docker of bitwarden_rs/vaultmaster - it comes w/ e-mail setup in the container, so one less thing to worry about… I had to swap around some docker-compose.yml ports and just point nginx-proxy-manager at it… this time, tho, I used the SSL certs from the docker; I didn’t wanna dig in and remove what they already had running.

    In the middle I was still fighting with myself and not taking ya’lls good suggestions - I tried to go the Cloudflared route; which is a cool service… but you can’t tunnel root domains unless you’re a paid user. Cloudflared tunnels would be great for exposing the Plex, TrueNAS, etc’s of the world… but I didn’t NEED/want subnets.

    Thanks to the Beehaw community… TechHeart.life is up and running. :P (Don’t worry, the Bitwarden is on a private domain. Phhhbbbbtttt.)

  • pAULIE42o@beehaw.orgOP
    link
    fedilink
    arrow-up
    1
    ·
    1 year ago

    Everyone here is awesome for ALL the replies. :P Thank you!!

    I decided to try a Cloudflared tunnel, but that didn’t work out because I can’t get the main domain1.com domain to go thru the tunnel… only ‘apps’, like blog.domain1.com. :P

    And, I’m still ironing out how to pass nginx to another local IP on my network; I just haven’t gotten it to click yet. All the info needed is right here - I promise to come back when I iron out the setup and post how I managed to do it…

    I can figure out how to pass nginx [or apache2, for that matter] to another PORT on the same local IP - I think I have both domains listening on ports 80/443 - and I’ll have to change that in order to route the data correctly… let alone getting out to another local IP.

    Again appreciate all the info - sometimes I just have to learn a bit more since I have all the documents right here. :P