alwinc
alwinc

Reputation: 1327

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?

Upvotes: 12

Views: 35065

Answers (2)

Thiago Curvelo
Thiago Curvelo

Reputation: 3740

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.

Upvotes: 28

Jon Lin
Jon Lin

Reputation: 143886

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.

Upvotes: 4

Related Questions