Route two domains to same JBoss instance
I have two public websites (foo.com and bar.com) that are pointed to a hardware load balancer. This hardware forwards the traffic to my server as follows:
http://foo.com ==> port 7700
https://foo.com ==> port 7701http://bar.com ==> port 7800
https://bar.com ==> port 7801My server is currently an old iPlanet box that defines two virtual servers (foo.com for 7700, 7701 and bar.com for 7800, 7801). Since the load balancer forwards directly to these ports, everything works fine.
I now need to port these website to an Apache 2.2 + JBoss 6.0 configuration, and I'm currently at a loss as to what the best practice is to accomplish this.
I've already set up Apache to listen on my four ports (7700,7701,7800, 7801) and configured SSL for 7701,7801. I'm assuming it is preferred to let Apache handle the SSL handshakes and connections. I have set up 4 Virtual Host entries in Apache, as follows:
<VirtualHost *:7700>
DocumentRoot "/htdocs/foo.com"
ServerName foo.com
</VirtualHost>
<VirtualHost *:7701>
Documen开发者_Python百科tRoot "/htdocs/foo.com"
ServerName foo.com
SSLEngine on
SSLCipherSuite ALL:...
SSLCertificateFile "/cert/foo.com.crt"
SSLCertificateKeyFile "/cert/foo.com.key"
</VirtualHost>
<VirtualHost *:7800>
DocumentRoot "/htdocs/bar.com"
ServerName bar.com
</VirtualHost>
<VirtualHost *:7801>
DocumentRoot "/htdocs/bar.com"
ServerName bar.com
SSLEngine on
SSLCipherSuite ALL:...
SSLCertificateFile "/cert/bar.com.crt"
SSLCertificateKeyFile "/cert/bar.com.key"
</VirtualHost>
I've tested this with static content, and both the HTTP and HTTPS connections are working correctly.
For my JBoss configuration, I currently have my applications deployed as /foo and /bar, although I don't know if that should be the final configuration. What I want to accomplish is this:
Forward all traffic from 7700/7701 to http://localhost:8080/foo, and from 7800/7801 to http://localhost:8080/bar. I don't want to see the /foo and /bar in the public URL, though - the user should just see http://www.foo.com and http://www.bar.com.
Is there a way to configure mod_jk to forward requests to a specific URL? Or should I be looking at ways to have JBoss host foo.com on port A and bar.com on port B -- and just have mod_jk forward to each port separately?
I think mod_jk
combined with URL rewriting should handle what you need. The mod_jk
information on workers indicates that you should be able to use mod_jk to forward requests based on URL using the uriworkermap. It's also mentioned that you can have a separate uriworkermap for each virtual host.
I'd also like to suggest that you take a look at mod_cluster
- it might have additional capabilities that would help with this.
EDIT
Argh. After your clarification (and some better digging), I think there may be a different answer. I am currently using ProxyPass
/ProxyPassReverse
to redirect top-level URLs to individual servlets. I've reviewed the Apache VirtualHost docs again, and I think that if you combine that with mod_proxy
, you'll be able to get what you want.
Here's a proposed configuration example that builds on what I have and could meet your specifications:
Listen 7700
Listen 7701
Listen 7800
Listen 7801
<VirtualHost *:7700>
ProxyPreserveHost On
ProxyPass / http://localhost:8080/foo
ProxyPassReverse / http://localhost:8080/foo
ServerName foo.com
</VirtualHost>
<VirtualHost *:7701>
ProxyPreserveHost On
ProxyPass / http://localhost:8080/foo
ProxyPassReverse / http://localhost:8080/foo
ServerName foo.com
SSLEngine on
SSLCipherSuite ALL:...
SSLCertificateFile "/cert/foo.com.crt"
SSLCertificateKeyFile "/cert/foo.com.key"
</VirtualHost>
<VirtualHost *:7800>
ProxyPreserveHost On
ProxyPass / http://localhost:8080/foo
ProxyPassReverse / http://localhost:8080/foo
ServerName bar.com
</VirtualHost>
<VirtualHost *:7801>
ProxyPreserveHost On
ProxyPass / http://localhost:8080/foo
ProxyPassReverse / http://localhost:8080/foo
ServerName bar.com
SSLEngine on
SSLCipherSuite ALL:...
SSLCertificateFile "/cert/bar.com.crt"
SSLCertificateKeyFile "/cert/bar.com.key"
</VirtualHost>
I apologize for missing this the first time. The only thing you'll want to test is to make sure that the URLs for servlet access are correct. The pattern I have in use is http://{host}:{port}/{WARName}/{ServletPath}
. If you've already tested the configuration with static content, only the proxy setup should need to be added/tuned. I'm not sure if you'll need the Listen
statements or not; I think you will, as your ports are non-standard.
精彩评论