问题
I have two different domain & sub domain.
For example :-
Domain 1 :- example1.com IP :- XXX.XX.XX.201
Domain 2 :- example2.com IP :- XXX.XX.XX.202 (This is a virtual hosting on above IP addr XXX.XX.XX.201)
I am also using sub-domains for the same like,
Domain 1 :- test.example1.com IP :- XXX.XX.XX.201
Domain 2 :- test.example2.com IP :- XXX.XX.XX.202 (This is a virtual hosting on above IP addr XXX.XX.XX.201)
I have to access the application in such way that if i access example.com it will redirect to me app1 and test.example.com will redirect mi to app2.
I have done some configuration related to this in my server.xml of tomcat.
<Host name="localhost" appBase="webapps"></Host>
<Host name="example2.com" appBase="webapps_example2">
<Alias>test.example2.com</Alias>
</Host>
If i hit URL like,
1.
http://example2.com -> I want to show an application app1
2.
http://test.example2.com -> I want to show an application app2
I have deployed app1 in webapps_example2 & when i hit any of the above URL .. both the URL redirecting to the same app1
. Where should i deploy my app2
so it will be accessible by above url no 2.
Note :- test.example.com is a just sample url & sub-domains may be change anytime so i can't put separate virtual host for entry & webapps folder for each sub domain.
app1 is simple html website & app2 is an J2EE application
Can anyone help me for doing this ???
Thanks in advance...
回答1:
<Connector port="80" ... />
<Engine name="Catalina" defaultHost="localhost">
<Host name="example.com" appBase="webapps-example"></Host>
<Host name="test.example.com" appBase="webapps-test.example"></Host>
</Engine>
Now, move app1
to webapps-example/ROOT
(case matters) (you ought to have webapps-example/ROOT/WEB-INF/web.xmlfor example) and move
app2to
webapps-test.example/ROOT`.
That ought to do it for example.com
. You can do the same for example2.com
, etc.
If you want a hostname to map to a single web application, you must name the web application ROOT
and put it into its own "webapps" (appBase
) directory. You will have to duplicate the <Host>
configuration for every virtual host you want to support.
If you are more relaxed about your requirements, you can do things in a more flexible way without having to define all those <Host>
elements.
来源:https://stackoverflow.com/questions/26421521/two-domain-their-sub-domain-are-mapped-to-the-same-ip-so-how-can-i-host-my-dif