Reverse Proxy Help/Advice reddit / selfhosted ---------------------------------------------------------------------- meddig0 · 2023-10-10 07:47 *Solved.* I have NPM working and pointing to a couple of docker services already, such as a Rainloop container. I'd like to now host either an Apache or Nginx container for a PHP site I'm building. For the life of me I can not get NPM to proxy to one of these containers. I've tried every article and tutorial I can find to no avail. The browser just says "We can’t connect to the server at [sub.domain.com](https://sub.domain.com/)". If I expose the ports (eg 8000:80) in the composer YML I can at least go to [domain.com](https://domain.com/):8000 and get a "File not found" message. I've tried proxying to both the container name (like I have done with Rainloop) and the internal network IP directly. Has anyone done this or can anyone point me in the direction of the one guide I've overlooked that will help or am I just simply barking up the wrong tree and I should just build a normal LAMP stack and forget about using NPM for this? Thanks. ---------------------------------------------------------------------- Bekar_vai · 2023-10-10 08:57 Did add a dns entry for you subdomain pointing to your ip? ---------------------------------------------------------------------- meddig0 · 2023-10-10 09:07 You know when you get hit with a quick oneliner that makes you realise that, for the last few hours of work, you've just been banging your head against a wall that isn't going to budge? Thank you, kind stranger, for not making me feel like *too much* the fool. I'm going to go and set this up now... Fucking DNS entry... what a moron I am. Ironically, for work we install servers into clients networks and guess what job isn't done by the client 9 out of 10 times? ---------------------------------------------------------------------- thekrautboy · 2023-10-10 09:12 A mistake i see many beginners making is to point the reverse proxy at the wrong container port. So assuming your NPM and Apache are both running as containers and both on the same Docker host. Place them together in a Docker network, typically you create a dedicated network "proxy" or something, then add only those containers to it that will actually get proxied. Then NPM needs to point at the internal container port of Apache, not the external which is just a mapping on the Docker host for access without the proxy. So in your example of 8000:80 then NPM needs to point at 80, not 8000. In addition, once the proxy setup is working you can (and probably should) remove the entire port mapping. Unless you need direct access to that Apache, bypassing the proxy. And you absolutely should use the container name as hostname to point the proxy at Apache, not a Docker IP. Grz used to defining useful and unique containernames for your services in your Docker compose files. ---------------------------------------------------------------------- meddig0 · 2023-10-10 09:12 Shockingly, I know, that has worked. Thank you again! ---------------------------------------------------------------------- meddig0 · 2023-10-10 09:23 Thanks for your reply, another comment, and your final paragraph, was what I had forgotten. Just a DNS entry. ---------------------------------------------------------------------- Bekar_vai · 2023-10-10 09:25 welp, as all great sysadmin like to say [It's always DNS](https://i.redd.it/sxudzlhamha51.png) ---------------------------------------------------------------------- meddig0 · 2023-10-10 09:26 It makes for a wonderful whipping post! ---------------------------------------------------------------------- thekrautboy · 2023-10-10 09:28 Good. Fyi if you find that most of your redirecting happens to the same Docker host (IP) you can consider adding a single wildcard CNAME `*` to your DNS, and that will redirect any undefined subdomain to the proxy. And it was probably just a bad example used by you, but please do not use things like `sub.domain.com` even for your private home network. Just TLD that are designated for that, such as `example.lan` or `example.private` or `example.home.arpa`. Or if you want to add valid SSL certs from Lets Encrypt to your NPM later on, you need to use existing domains which you actually own. Can be done simply with a free provider like duckdns.org or dedyn.io and you get a setup like `apache.local.example.dedyn.io`