一、添加网页
1、全局访问
# cd /usr/local/bin/tomcat/webapps/ROOT/
# vim test.jsp
<%@ page language= "java" import= "java.util.*" pageEncoding= "UTF-8"%>
<html>
<head>
<title>JSP test1 page</title>
</head>
<body>
<% out.println("www.tomcat-test1.com");%>
</body>
# cd /usr/local/bin/tomcat/work/Catalina/localhost/ROOT/
# cd org/apache/jsp/
# ls
index_jsp.class index_jsp.java test_jsp.class test_jsp.java
# cat test_jsp.java //查看转换后的文件
......
out.write("\n");
out.write("<html>\n");
out.write(" <head>\n");
out.write(" <title>JSP test1 page</title>\n");
out.write(" </head>\n");
out.write("<body>\n");
out.write(" ");
out.println("www.tomcat-test1.com");
out.write("\n");
out.write("</body>\n");
out.write("</html>\n");
......
2、缺省访问
# mkdir -p /web/webapps/myapp
# vim /web/webapps/myapp/index.jsp
<%@ page language= "java" import= "java.util.*" pageEncoding= "UTF-8"%>
<html>
<head>
<title>JSP test2 page</title>
</head>
<body>
<% out.println("www.tomcat-test2.com");%>
</body>
# cp -r /web/webapps/myapp/ /usr/local/bin/tomcat/webapps/
3、虚拟主机配置
定义一个虚拟主机,在Tomcat配置文件Host段下方进行添加context段,将网站文件路径指向已经建立的/web/webapp1/
# mkdir /web/webapps/Root
# vim /web/webapps/Root/test.jsp
<%@ page language= "java" import= "java.util.*" pageEncoding= "UTF-8"%>
<html>
<head>
<title>JSP test3 page</title>
</head>
<body>
<% out.println("www.tomcat-test3.com");%>
</body>
</html>
# vim /usr/local/bin/tomcat/conf/server.xml
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Context docBase="/web/webapp1" path="" reloadable="false">
</Context>
# /usr/local/bin/tomcat/bin/shutdown.sh
# /usr/local/bin/tomcat/bin/startup.sh
参数 | 说明 |
---|---|
docBase | web应用的文档基准目录 |
reloadable | 设置监视“类” 是否变化 |
path="" | 设置默认"类“ |
二、添加管理用户(生产环境建议关闭)
1、更改后台关闭功能
# vim /usr/local/bin/tomcat/conf/server.xml
<Server port="8005" shutdown="8371728193424254">
<Listener className="org.apache.catalina.startup.VersionLoggerListener" />
2、添加管理用户
想要对Tomcat管理,就必须创建Tomcat的管理账户,打开Tomcat的配置文件tomcat-users.xml,在tomcat-users模块中加入如下内容:
<role rolename="admin-gui"/>
<role rolename="admin-script"/>
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>
<user username="tomcat" password="tomcat" roles="manager-gui,manager-script,manager-jmx,manager-status,admin-script,admin-gui"/>
上述配置中,role元素表示了Tomcat管理的身份,一共有6种,这6种身份及其权限如下所示:
- manager-gui:允许通过web的方式登录查看服务器信息
- manager-script:允许以纯文本的方式访问
- manager-jmx:允许jmx的代理访问
- manager-status:允许以只读状态访问
- admin-gui:允许访问HTML GUI
- admin-script:允许访问文本接口
# vim /usr/local/bin/tomcat/conf/tomcat-users.xml
......
-->
<role rolename="manager-gui"/>
<role rolename="admin-gui"/>
<user username="lisi" password="123456" roles="manager-gui,admin-gui"/>
</tomcat-users>
# vim /usr/local/bin/tomcat/webapps/manager/META-INF/context.xml
<Context antiResourceLocking="false" privileged="true" >
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1|192.*" />
......
# vim /usr/local/bin/tomcat/webapps/host-manager/META-INF/context.xml
<Context antiResourceLocking="false" privileged="true" >
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1|192.*" />
# /usr/local/bin/tomcat/bin/shutdown.sh
# /usr/local/bin/tomcat/bin/startup.sh
评论区