How to point a subdomain to a specific IP with Apache?

February 7, 2017 640 views
Apache Python Ubuntu

Hello, I have a simple Bottle.py python app inside a docker container that exposes port 8081. If I visit my.droplet.ip:8081 the app shows up. Now, I want the app to be on sub.mydomain.tld. Please note that I am running Apache2 and mydomain.tld is not hosted on my droplet. How may I approach the problem?

2 Answers

You create an A-Record in your DNS panel that points to the desired IP address.

  • I have tried that earlier. I created a subdomain. Inside hostname, I entered @, inside 'will direct to' I entered my.droplet.ip:8081 but it says invalid IP address. Am I missing something?

@abhisekdutta

What you need to do is setup proxying. This can be done with Apache using mod_proxy and there's a guide for exactly that here at DigitalOcean.

https://www.digitalocean.com/community/tutorials/how-to-use-apache-as-a-reverse-proxy-with-mod_proxy-on-ubuntu-16-04

Without using a proxy, which internally accepts requests for domain.com or sub.domain.com and serves domain.com:2365 (or any application running on a port, just an example), you'd need to keep the ports in the URL's.

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.