How to set the tomcat server to directly access the project default page by entering the website domain name

Original address: http://www.2cto.com/os/201404/294617.html

This article has been slightly modified to be more in line with my own setup.

 

1. Do not write the port.

This question has been asked badly, because the default access port of TOMCAT is 8080, and the TCP/IP protocol defaults to 80 port access. The reason why everyone sees that other websites do not write the port number is because people use the 80 port to access. , and port 80 does not need to be written because of the default port of TCP/IP. If you want to change it, you can do it in the server.xml file in the conf file in the tomcat installation directory.

<Connector connectionTimeout="20000" port="80" protocol="HTTP/1.1" redirectPort="8443"/>

, the value of the port above TOMCAT is 8080 by default, I changed it to port 80 here, it's that simple. After that, you don't need to write the port when you access the project.

Second, the virtual directory configuration. ( I did not configure this step )

Take TOMCAT7 as an example here. Virtual directories exist in my opinion to hide real directories. The mapped real directory can be accessed indirectly through the virtual directory.

Open Tomcat7/conf/web.xml and
find <servlet>
<servlet-name>default</servlet-name>
<servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
<init-param>
< param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>listings</param-name>
<param-value >true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
Change false to true at <param-value> and
then open the server. xml
add <Context path="/virtual directory name" docBase="D:\Tomcat 7.0\folder name"/> before </host>

My configuration is like this:       

<Context path="/" docBase="../webapps/bianlee"  debug="0" reloadable="true"></Context>

之后,你就只能通过虚拟目录名来访问你的项目名了。

三、默认项目名(也就是不写)。

大家都知道,普通情况下我们访问TOMCAT服务器中的项目名时都是采用( http://localhost:8080/xx/index.jsp )来访问,其中localhost的指某个IP地址,8080是指访问TOMCAT的端口号(),xx为项目名,index.jsp为项目中的网页。

但大家经常在网上有很多网站我们直接输入域名就可以访问网站的网页了,这里先将域名等同于IP+端口吧。这些网站与我们自己做的网站有两点不同之处,其一就是不需要像我们访问自己的网站一样还要写项目名在后面,今天就与大家分享一下是怎么做到的。

其实很简单,先完成上面虚拟目录配置之后(主要是server.xm中的步骤,web.xml的步骤可以省略),将path的值设为“”就行了,以后访问项目就不需要写项目名了。

好了,上面三部完成后在自己电脑上直接访问localhost就可以访问项目中的默认网页了(不要告诉我你不知道如何设置项目的默认访问页。)

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327037273&siteId=291194637