Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I'm trying to set up Apache + Glassfish so that I can access two different webapps on the same physical host, differentiated by the hostname in the URL.

So if I visit http://host1.com, I'll get app1. If I visit http://host2.com, I'll get app2. host1 and host2 both resolve to the same IP address.

I've been able to get this working in a basic way with mod_proxy and Glassfish virtualservers using this guide. But the user still needs to specify the context-root for one of the apps, i.e. http://host1.com/app1.

How can I set things up so that both apps appear as the "root" in their respective URLs?

Do I need two separate Glassfish domains?

Here's the apache config I'm using:

<VirtualHost *:80>
     ProxyPreserveHost On
     ProxyPass / http://localhost:8080/app1
     ProxyPassReverse / http://localhost:8080/app1
     ServerName host1.com
</VirtualHost>

<VirtualHost *:80>
     ProxyPreserveHost On
     ProxyPass / http://localhost:8080/
     ProxyPassReverse / http://localhost:8080/app2
     ServerName host2.com
</VirtualHost>
share|improve this question

1 Answer 1

up vote 1 down vote accepted

I was close. Here's what ended up working:

Create a 2nd domain:

  • $ asadmin create-domain --portbase 5000 --profile developer mydomain
  • $ asadmin start-domain mydomain

Deploy both apps to the context root in their respective domains. You specify domain by giving the admin port:

  • $ asadmin deploy --contextroot "/" target/app1.war # domain1
  • $ asadmin deploy --contextroot "/" --port 5048 target/app2.war # mydomain

The new domain will run on port 5080, so configure mod_proxy to use that:

<VirtualHost *:80>
     ProxyPreserveHost On
     ProxyPass / http://localhost:8080/
     ProxyPassReverse / http://localhost:8080/
     ServerName host1.com
</VirtualHost>

<VirtualHost *:80>
     ProxyPreserveHost On
     ProxyPass / http://localhost:5080/
     ProxyPassReverse / http://localhost:5080/
     ServerName host2.com
</VirtualHost>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.