Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Subdomain proxy pass all pointing to single server

I have 2 applications hosted on a single apache tomcat on port 8080 >

  • http://mydomain.com:8080/application1
  • http://mydomain.com:8080/application2

I would like to run an apache proxy in front of BOTH of them with the following behaviour >

  • http://mydomain.com/* (apache2) -> http://mydomain.com:8080/application1/* (tomcat)
  • http://subdomain.mydomain.com/* (apache2) -> http://mydomain.com:8080/application2/* (tomcat)

The best I have got right now is 2 machines with different IPs and routing the domain and subdomains correspondingly.

Ideally I want the apache proxy and the 2 apps to be on the SAME machine...

Can anyone with kick arse DEVOps skills assist?

like image 995
alwinc Avatar asked Dec 09 '11 06:12

alwinc


2 Answers

In the virtualhost config for mydomain.com (apache), you need

ProxyPassMatch ^/(.*)$ http://mydomain.com:8080/application1/$1

In the virtualhost config for subdomain.mydomain.com (apache), you nede

ProxyPassMatch ^/(.*)$ http://mydomain.com:8080/application2/$1

Both config files should be on the same machine, and even the same file. See VirtualHost Examples for some examples on how this is setup.

like image 53
Jon Lin Avatar answered Oct 24 '22 09:10

Jon Lin


In addition to @Jon Lin answer, consider using ProxyPassReverse also, just in case your app do any redirects. It makes Apache correct URL's on responses (More about ProxyPassReverse). It will look like that:

<VirtualHost subdomain.mydomain.com:80>
    ProxyPass / http://localhost:8080/application1/
    ProxyPassReverse / http://localhost:8080/application1/
</VirtualHost>

<VirtualHost mydomain.com:80>
    ProxyPass / http://localhost:8080/application1/
    ProxyPassReverse / http://localhost:8080/application1/
</VirtualHost>

I hope it helps.

like image 36
Thiago Curvelo Avatar answered Oct 24 '22 09:10

Thiago Curvelo