trying to host multiple services on the same IP and am sorta confused - can anyone lead me in the right direction? reddit / selfhosted ---------------------------------------------------------------------- YeetMcManus · 2023-11-01 21:41 hey folks! finally starting with my homelab and i have adguard and homer up and running! i am having a couple of issues however, and i haven't really found much that makes sense to me yet (sorry - super new!): i'm on ubuntu server FWIW initially, i could only access the adguard web interface via the ip *with* the port number - i.e. [10.0.0.1:3000](https://10.0.0.1:3000); after i started up Homer, though, i could only access it *without* the port. not sure this is so much a problem, but i think it may have some impact on my actual problem, which is: i want to configure domain names for the services on my intranet, so i initially tried to use adguard to do this. my first problem arose when i couldnt type port numbers in the DNS rewrite, so i couldn't access my homer via DNS because that IP only redirected to my adguard. due to this, i read that possibly setting up nginx proxy manager and creating a reverse proxy would be good practice so that the proxy could divvy up the domain names itself. so i spun that up in docker, but now i can't start adguard because port 443 is taken by nginx (which i thought could solve this port conflict issue?) - any idea how i can go about this to allow both adguard to run with nginx *and* help solve my domain name issue with nginx? ​ i'm just looking for some general direction to help my understanding - definitely don't want y'all to do homework for me haha; and apologies if these are dumb questions - genuinely just trying to skill up in linux b/c this is the first time i've seriously used it ---------------------------------------------------------------------- mistersinicide · 2023-11-01 21:53 How is everything deployed? Is it all docker? It sounds like you're trying to expose the same ports from multiple containers, which will lead to a conflict. But you're going down the right path using a Proxy Manager to route requests to the various containers (e.g. adguard and homer) ---------------------------------------------------------------------- unrealmaniac · 2023-11-01 22:18 if it's just all docker, couldn't you move nginx to external port 8443 or something else to remove the conflict? ---------------------------------------------------------------------- YeetMcManus · 2023-11-01 22:25 thank you! yes it is all docker - in all honesty i wasn’t sure that i could get around having to expose those same ports since i figured they were all necessary for every service - is that not the case? ---------------------------------------------------------------------- YeetMcManus · 2023-11-01 22:26 honestly didn’t know that i could do that lol; from there, could i use the reverse proxy to route the different services across different domain names? ---------------------------------------------------------------------- SagaciousZed · 2023-11-01 22:26 Remember that http service defaults to port 80 and https service defaults to port 443. Only one service can bind and listen on one port per host. This means you cannot have two services bound and listening on the same port. A reverse proxy can be configured with virtual hosts that looks at the target host of an http request and proxying the connection to another port on the machine. This way, your browser can always talk to the host on the default port, and the reverse proxy will communicate with the service hosted on another port, at least when everything is bound and listening on the same machine. In your particular instance, you want nginx (as your reverse proxy) to be listening on the default https port of 443 and configure adguard to listen on another port. Small caveat while using things like docker. It is possible to avoid configuring a service to listen on another port if it is running in docker by either having docker do the port mapping or relying on docker networking configuration in conjunction with the reverse proxy to avoid any services binding to a port on the docker host / physical host directly. ---------------------------------------------------------------------- YeetMcManus · 2023-11-01 22:29 also ty!!! ---------------------------------------------------------------------- mistersinicide · 2023-11-01 22:33 In docker, you only need to expose ports if you need to directly access that container on that port. Otherwise you don't have to expose the port. For example with Homer, the examples, show that you'd map port 8080 on your host machine to the container on the same port. But you could also map a different external port to the same container port, e.g. 8181 on host -> 8080 on container. But let's say you have a Proxy Manager like Nginx/Traefik, you can then choose to expose no ports on Homer, and only expose 80/443 on Proxy Manager, so long as both containers (Homer and Nginx) are on the same Docker network, they can communicate to each other. So you can then expose port 80 on Proxy Manager, and Proxy Manager can communicate and redirect to Homer on 8080. I don't have any specific docker-compose examples nor do I use Nginx Proxy Manager, but I'm sure the public docs for it should provide you with examples or something. ---------------------------------------------------------------------- unrealmaniac · 2023-11-01 23:12 I've actually stuffed this up a bit in my initial reply. you would want the proxy server on ports 80 & 443 externally & move the other service (homer?) to something else like 8443. then setup your nginx proxy hosts to something such as: - proxy.example.com -> 10.0.0.1:443 - homer.example.com -> 10.0.0.1:8443 - adguard.example.com -> 10.0.0.1:3000 yes, after you setup the nginx proxy. you'll need to setup your DNS re-wirites to point to the proxy server. Or, just do a wildcard re- write: - *.example.com -> 10.0.0.1 ---------------------------------------------------------------------- mdjmrc · 2023-11-02 04:42 The easiest way to look at it is from the perspective of OSI model. Let’s say you start from layer 3 with a single IP address. That one address can be reached via 65k ports, so the easiest way to differentiate services is to use different ports for each service - with ports being defined at layer 4. The ‘problem’ is when you want to serve instances of the same service on the same port. At that point you have to go even higher, and that’s where the reverse proxy jumps in. RPs operate at layer 7, where they can differentiate between different names and point to a specific one as they create a mapping between the name itself and the underlying service. That’s why you can have multiple instances of the same service listening on the same port, with the differentiator being the name of the service: www.domain.com, web.domain.com, pages.domain.com, etc. If this doesn’t make sense, I would suggest doing a little bit of a research on the networking side to understand how data is being transferred. ---------------------------------------------------------------------- mss-cyclist · 2023-11-02 05:42 Yes. Make sure every web service you want to expose is running on a different port. The proxy manager is the only one on ports 80 / 443. It will forward requests to your services based on the url you hit the proxy with. ---------------------------------------------------------------------- YeetMcManus · 2023-11-02 22:12 i think this did the trick for me - i knew so little about docker networking that i didnt put 2 and 2 together to realize the leftmost port value was the host port and the rightmost was the container port thanks a ton for your super detailed and helpful explanation! ---------------------------------------------------------------------- YeetMcManus · 2023-11-02 22:16 holy moly you just figured out the whole thing for me lol, thank you *so* much - i have my goofy domain names set up now! really appreciate your super helpful explanation ---------------------------------------------------------------------- mistersinicide · 2023-11-03 00:23 Cool, I'm glad you were able to arrive at a solution. Happy Self- Hosting! ---------------------------------------------------------------------- YeetMcManus · 2023-11-03 01:20 thanks so much! i definitely get why people are into this lol, it can be frustrating to learn but it is genuinely addicting and i’ve learned a lot about linux just from this