Forwarding IP:Port -> Registered Domain Name

November 9, 2018 1.4k views
DigitalOcean Deployment Ansible Development Ubuntu 16.04

Hello,

How does one forward IP:PORT to registered domain name?
so instead of the IP:PORT appearing in the address bar, the registered domain name appears instead.

1 Answer

Hey friend!

This is a great question, and a fairly common concern. The first key is to move out of the mindset of forwarding it via DNS, which is what almost everyone thinks of first in the process. DNS is merely a name translated to IP, so 1.1.1.1:3000 after DNS = mydomain.com:3000, as DNS cannot mask a port.

(I’m using 1.1.1.1 as a sample IP address for this post)

The second key is to recognize how ports are masked by web browsers:

  1. https://mydomain.com = mydomain.com:443 = 1.1.1.1:443
  2. http://mydomain.com = mydomain.com:80 = 1.1.1.1:80

Web browsers mask ports 443 and 80 via https or http, as that value instructs the browser to connect on one of those two ports. So what you need to do is have your application served via port 443 (with SSL certificate) or port 80 (no SSL). One way to do this is to change your application configuration to make it listen on one of those ports. Another way is to use a reverse proxy. A reverse proxy takes in requests on port 80 or 443, pulls data from the other port, and serves it to the visitor over the common ports.

Here’s a tutorial for using Apache as a reverse proxy:
https://www.digitalocean.com/community/tutorials/how-to-use-apache-as-a-reverse-proxy-with-mod_proxy-on-ubuntu-16-04

Jarland

by Mateusz Papiernik
In this tutorial, you will set up Apache as a reverse proxy using the `mod_proxy` extension to redirect incoming connections to underlying application server(s) running on the same network. There are instructions on setting up a simple web app using the Flask framework to show how Apache interacts with the real application hidden behind it, but you can also follow this tutorial using your existing application server, if you have one.
Have another answer? Share your knowledge.