开发者

Direct root domain to a context and subdomain to another context

I have situation where i want to direct my root domain i.e. www.abc.com to a context in tomcat and *.abc.com to another context in tomcat.

curr开发者_StackOverflow中文版ently www.abc.com abc.com and *.abc.com all point to my ROOTcontext in tomcat but I want

www.abc.com and abc.com to point to ROOT and

*.abc.com to some other context in tomcat.


This is an old one, but since I reach here from Google's first page, it deserves an answer.

I guess the best shot is to add "VirtualHost"s to your httpd and "Host"s to your tomcat's server.xml for each subdomain. Take this as a "HelloMultiWorld" example:

<VirtualHost *:80>
  ServerName abc.com
  ServerAlias www.abc.com sd1.abc.com
  ...
  ProxyPreserveHost true
  ProxyPass / ajp://localhost:8009/
  ProxyPassReverse / ajp://localhost:8009/
  ...
</VirtualHost>

And, in Tomcat's server.xml:

<Engine defaultHost="localhost" ...>
  ...
  <Host name="localhost" appBase="webapps" ...>...</Host>
  <Host name="sd1.abc.com" appBase="webapps-sd1"...>...</Host>
</Engine>

Obviously, you need a "webapps" and a "webapps-sd1" folder with their own ROOT.war.

With this configuration, HTTPd will proxy all abc.com, www.abc.com and sd1.abc.com requests to Tomcat (using AJP - you can also use HTTP/8080). Tomcat will receive a request with a "Host: xxx.abc.com" HTTP header (because of "ProxyPreserveHost"). With multiple "Host"s in server.xml, it will route the request according to the "Host" header. All unidentified hosts will route to 'defaultHost'.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜