Uncategorized

Stupid question about reverse proxys and related: Any way to use the same url internally and externally but without round tripping through the internet when local?

Using the Same URL Internally and Externally: A Reverse Proxy Conundrum

A Common Problem for Self-Hosted Services

So, you’ve set up your own domain and subdomains for various services, like plex.mydomain.com or blog.mydomain.com. That’s easy enough, with plenty of options available for reverse proxies, Cloudflare, Pangolin tunnels, Tailscale, VPNs, and more. But, have you ever stopped to think about how your self-hosted services behave when you access them from within your local network versus from outside?

I recently stumbled upon a Reddit post that got me thinking about this very issue. The author, u/chazwhiz, asked if there’s a way to use the same URL for both internal and external access, without having to round-trip through the internet when accessing the service from within their local network. It’s a great question, and one that I think many of us can relate to.

The Problem with Round-Tripping

When you access your self-hosted service using its external URL, like plex.mydomain.com, the request has to travel all the way to your router, then back to your server, even if you’re sitting right next to it. This can introduce latency, slow down the service, and even increase your internet bandwidth usage. It’s like taking a detour around the block to get to your own backyard.

But, if you use the internal IP address and port number, like 192.168.1.100:32400, you can access the service directly, without having to go through the internet. The problem is, you’d have to remember two different URLs, which can be inconvenient and prone to errors.

A Solution to the Problem

So, is there a way to use the same URL for both internal and external access, without having to round-trip through the internet? The answer is yes, and it involves using a combination of DNS and routing tricks. One approach is to use a local DNS server, like dnsmasq or Unbound, to resolve the external URL to the internal IP address when you’re on the local network.

Another approach is to use a reverse proxy, like NGINX or Apache, to handle requests from both internal and external sources. You can configure the proxy to use the internal IP address when the request comes from the local network, and the external URL when the request comes from outside.

Configuring the Solution

Configuring the solution involves a few steps, including setting up the local DNS server or reverse proxy, and updating the DNS records for your domain. It’s not a trivial task, but it’s definitely doable with some patience and persistence.

Here are the general steps you can follow:

  • Set up a local DNS server, like dnsmasq or Unbound, on your router or a dedicated machine.
  • Configure the DNS server to resolve the external URL to the internal IP address when you’re on the local network.
  • Set up a reverse proxy, like NGINX or Apache, to handle requests from both internal and external sources.
  • Configure the proxy to use the internal IP address when the request comes from the local network, and the external URL when the request comes from outside.

Conclusion

In conclusion, using the same URL for both internal and external access to your self-hosted services is possible, but it requires some creativity and technical know-how. By using a combination of DNS and routing tricks, you can avoid the round-trip through the internet and access your services directly, without having to remember two different URLs.

I hope this helps, and happy self-hosting!

Korzystanie z tego samego adresu URL wewnętrznie i na zewnątrz: problem z odwrotnym serwerem proxy

Typowy problem dla usług hostowanych samodzielnie

Więc, ustawisz własną domenę i poddomeny dla różnych usług, jak plex.moja-domena.pl lub blog.moja-domena.pl. To jest łatwe, z wieloma dostępnymi opcjami dla serwerów proxy, Cloudflare, tuneli Pangolin, Tailscale, VPN i więcej. Ale, czy kiedykolwiek zatrzymałeś się, by pomyśleć o tym, jak twoje usługi hostowane samodzielnie zachowują się, gdy dostęp do nich uzyskujesz z sieci lokalnej, a gdy uzyskujesz dostęp z zewnątrz?

Niedawno natknąłem się na post na Reddit, który zaciekawił mnie tym problemem. Autor, u/chazwhiz, zapytał, czy jest sposób, by używać tego samego adresu URL dla dostępu wewnętrznego i zewnętrznego, bez konieczności przejścia przez internet, gdy uzyskuje się dostęp do usługi z sieci lokalnej. To jest doskonałe pytanie, i myślę, że wiele z nas może się z nim utożsamiać.

Problem z przejściem przez internet

Gdy uzyskujesz dostęp do swojej usługi hostowanej samodzielnie, używając jej zewnętrznego adresu URL, jak plex.moja-domena.pl, żądanie musi przejść przez cały sposób do twojego routera, a następnie z powrotem do twojego serwera, nawet jeśli siedzisz obok niego. To może wprowadzić opóźnienia, spowolnić usługę i nawet zwiększyć użycie przepustowości internetu. To jest jak robienie objazdu dookoła bloku, by dostać się do własnego podwórka.

Ale, jeśli użyjesz wewnętrznego adresu IP i numeru portu, jak 192.168.1.100:32400, możesz uzyskać dostęp do usługi bezpośrednio, bez konieczności przejścia przez internet. Problem polega na tym, że musisz pamiętać dwa różne adresy URL, co może być niewygodne i podatne na błędy.

Rozwiązanie problemu

Czy jest sposób, by używać tego samego adresu URL dla dostępu wewnętrznego i zewnętrznego, bez konieczności przejścia przez internet? Odpowiedź brzmi tak, i polega na używaniu kombinacji sztuczek DNS i routingowych. Jednym z podejść jest użycie lokalnego serwera DNS, jak dnsmasq lub Unbound, do rozwiązania zewnętrznego adresu URL do wewnętrznego adresu IP, gdy jesteś w sieci lokalnej.

Innym podejściem jest użycie serwera proxy, jak NGINX lub Apache, do obsługi żądań z obu źródeł, wewnętrznych i zewnętrznych. Możesz skonfigurować serwer proxy, by używał wewnętrznego adresu IP, gdy żądanie pochodzi z sieci lokalnej, i zewnętrznego adresu URL, gdy żądanie pochodzi z zewnątrz.

Konfigurowanie rozwiązania

Konfigurowanie rozwiązania wymaga kilku kroków, w tym ustawienia lokalnego serwera DNS lub serwera proxy, oraz aktualizacji rekordów DNS dla twojej domeny. To nie jest trywialne zadanie, ale jest możliwe z trochę cierpliwości i wytrwałości.

Oto ogólne kroki, które możesz wykonać:

  • Ustaw lokalny serwer DNS, jak dnsmasq lub Unbound, na twoim routerze lub dedykowanej maszynie.
  • Skonfiguruj serwer DNS, by rozwiązał zewnętrzny adres URL do wewnętrznego adresu IP, gdy jesteś w sieci lokalnej.
  • Ustaw serwer proxy, jak NGINX lub Apache, do obsługi żądań z obu źródeł, wewnętrznych i zewnętrznych.
  • Skonfiguruj serwer proxy, by używał wewnętrznego adresu IP, gdy żądanie pochodzi z sieci lokalnej, i zewnętrznego adresu URL, gdy żądanie pochodzi z zewnątrz.

Podsumowanie

Podsumowując, używanie tego samego adresu URL dla dostępu wewnętrznego i zewnętrznego do twoich usług hostowanych samodzielnie jest możliwe, ale wymaga trochę kreatywności i wiedzy technicznej. Używając kombinacji sztuczek DNS i routingowych, możesz uniknąć przejścia przez internet i uzyskać dostęp do twoich usług bezpośrednio, bez konieczności pamiętania dwóch różnych adresów URL.

Mam nadzieję, że to pomoże, i szczęśliwego hostowania!

Leave a Reply

Your email address will not be published. Required fields are marked *

WordPress Appliance - Powered by TurnKey Linux