1.tomcat安装 安装JDK wget http://download.oracle.com/otn-pub/java/jdk/8u181-b13/96a7b8442fe848ef90c96a2fad6ed6d1/jdk-8u181-linux-x64.rpm?AuthParam=1537143448_6a9af1d6a014843d90b0a3a435ab62ae rpm -ivh jdk tar -axf apache-tomcat-8.0.30 mv apache-tomcat-8.0.30 /usr/local/tomcat 修改配置文件 vim /usr/local/tomcat/conf/server.xml 注释掉以下内容 <!-- <Connector port "8009" protocol="AJP/1.3" redirectPort="8443" /> --> 创建测试JSP页面 vim /usr/local/tomcat/webapps/ROOT/test.jsp now time is : <%=new java.util.Date()%> 启动服务验证 sh /usr/local/tomcat/bin/startup.sh netstat -anptu |grep java 客户端访问测试: firefox http://127.0.0.1:8080/test.jsp 2.部署tomcat加密虚拟主机 实现两个基于域名的虚拟主机,域名分别为www.test.com 和www.tomcat.com 页面访问路径分别为/usr/local/tomcat/test/ROOT和/usr/local/tomcat/tomcat/tom/ROOT 访问页面支持SSL加密通讯 私钥整数路径为/usr/local/tomcat/conf/cert 每个虚拟主机都拥有独立的访问日志文件
修改server.xml文件,创建虚拟主机: <Host name="www.test.com" appBase="test" unpackWARs="true" autoDeploy="true"></Host> <Host name="www.tomcat.com" appBase="tom" unpackWARs="true" autoDeploy="true"></Host>
创建页面路径和文件 mkdir /usr/local/tomcat/{test,tom}/ROOT echo "test.com" >/usr/local/tomcat/test/ROOT/index.html echo "tomcat.com" >/usr/local/tomcat/test/ROOT/index.html
创建加密用的私钥和证书文件 keytool -genkeypair -alias tomcat -keyalg RSA -keystore /usr/local/tomcat/conf/keystore
修改server.xml配置文件,创建加密连接的Connector vim /usr/local/tomcat/conf/server.xml <Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol" maxThreads="150" SSLEnabled="true" scheme="https" secure="true" keystoreFile="/usr/local/tomcat/conf/keystore" keystorePass="123456" clientAuth="true" sslProtocol="TLS" /> 为每个虚拟主机设置不同的日志文件: <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="test_access" suffix=".log" pattern="common" /> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="tomcat_access" suffix=".log" pattern="common" /> 重启apache服务器,测试访问效果。
firefox http://www.test.com:8080 firefox http://www.tomcat.com:8080 firefox http://www.test.com:8443 firefox http://www.tomcat.com:8443