Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use apache to redirect to docker container

I have two docker containers running Tornado applications, named app1 and app2 on a Ubuntu VM. The VM has a domain name ubuntu.somesite.com. I can access one of them with docker port forwarding at ubuntu.somesite.com:8080. Instead I want both apps to be accessible at ubuntu.somesite.com/app1 and ubuntu.somesite.com/app2. What would be the best way to accomplish this? I tried using apache virtual hosts but didn't get very far.

like image 589
yam Avatar asked Sep 07 '17 14:09

yam


1 Answers

You need to expose both docker containers on the host network, of course on two different ports (let's say 8080 and 8081).

Than you need a reverse proxy in your host. Apache 2.4 is one possible choice. You could use a virtualhost like this:

<VirtualHost *:80>
  ServerName ubuntu.somesite.com

  <Location />
    Order allow,deny
    Allow from all
    Require all granted
  </Location>

  ProxyPass /app1 http://127.0.0.1:8080/
  ProxyPassReverse /app1 http://127.0.0.1:8080/

  ProxyPass /app2/ http://127.0.0.1:8081/
  ProxyPassReverse /app2/ http://127.0.0.1:8081/
</VirtualHost>

Please note that this config will not work with apache 2.2 or older.

like image 169
whites11 Avatar answered Sep 26 '22 21:09

whites11