tomcat中间件访问根域名直接跳转某个应用的首页

背景

80端口是比较特殊的端口,是域名默认端口,比如域名是http://www.text.com,将它当成官网的域名,一般直接访问域名即跳出官网的首页,如何设置呢?

部署一个应用

比较简单,配置server.xml即可达到目的.
比如有个应用是xny,在server.xml的Host标签下增加如下:

 <Context docBase="xny" path="/" reloadable="true" source="org.eclipse.jst.jee.server:LeanFileUpload"/>

设置了xny的应用的访问路径是”/”
当我们访问http://www.text.com域名时后查询访问路径是”/”的应用,这里就是xny.

部署多个应用

当存在多个应用是一个tomcat下时,如果还是按如上设置如报”WARNING: A context path must either be an empty string or start with a ‘/’ and do not end with a ‘/’. The path [/] does not meet these criteria and has been changed to []”错误,这时候就不能如上修改server.xml了.
修改webapps/ROOT下的index.jsp文件.
如下

<%
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy");
request.setAttribute("year", sdf.format(new java.util.Date()));
request.setAttribute("tomcatUrl", "http://tomcat.apache.org/");
request.setAttribute("tomcatDocUrl", "/docs/");
request.setAttribute("tomcatExamplesUrl", "/examples/");
%>

修改成

<%
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy");
request.setAttribute("year", sdf.format(new java.util.Date()));
request.setAttribute("tomcatUrl", "http://tomcat.apache.org/");
request.setAttribute("tomcatDocUrl", "/docs/");
request.setAttribute("tomcatExamplesUrl", "/examples/");

String contextP = request.getScheme()+"://"+request.getServerName();
String url = contextP + "/xny/index.html";
response.sendRedirect(url);
%>

其实访问根域名进会自动跳转到ROOT应用的index.jsp页面,如果在这里把页面跳转到其它页面也能达到我们的目的,不过有个缺陷,地址url会变成http://www.text.com/xny/index.html

扩展

如果有需求访问一个应用跳转的应用在其它域名或tomcat下即可以修改ROOT下的index.jsp实现.

补充

通过阿里云的域名解析.
选择”隐性URL”,记录值不填IP,而是填要跳转的域名
这里写图片描述

还有一种方式即Nginx代理模式阿里云centos环境之nginx实站配置

总结
算下来最总有4种方式实现标题目的

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值