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

Posted February 7, 2017 12k views

Hello, I have a simple 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?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
2 answers


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.

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

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.

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