build a Web server based on Jdk+tomcat
First, pre-installation of software
1, jdk:centos7.2 default installation, you can check whether the installation
[email protected] ~]# Rpm-qa | grep jdk
Java-1.8.0-openjdk-1.8.0.65-3.b17.el7.x86_64
Java-1.8.0-openjdk-headless-1.8.0.65-3.b17.el7.x86_64
The above display has been installed, so do not need to install, if not installed, you can download the RPM package installation.
2, Tomcat:tomcat do not need to install, only need to unpack, move the directory to the installation directory
TAR-XF apache-tomcat-8.0.30.tar.gz
MV Apache-tomcat-8.0.30/usr/local/tomcat
/usr/local/tomcat/bin/startup.sh//Start Tomcat
/usr/local/tomcat/bin/shutdown//Turn Tomcat off
3, start the service, go to the client test, a simple website is built to complete
http://192.168.2.113:8080///Note Add the port number
Second, the configuration of the virtual host (a server, put two or more sites)
1. Edit profile: Vim/usr/local/tomcat/conf/server.xml
Unpackwars= "true" autodeploy= "true" >
</Host>
Unpackwars= "true" autodeploy= "true" >
</Host>
2. Create a directory of two Web files in the installation directory and create two different home files
Mkdir-p/usr/local/tomcat/aa/root/
Mkdir-p/usr/local/tomcat/bb/root/
echo "www.aa.com" >/usr/local/tomcat/aa/root/index.jsp
echo "www.bb.com" >/usr/local/tomcat/bb/root/index.jsp
3. Restart Service, test
4, the path of the site to jump. When accessing www.aa.com:8080/test, automatically jumps to /www/html/"(Create it Yourself)
Unpackwars= "true" autodeploy= "true" >
<context path= "/test" docbase= "/www/html/" reloadable= "true"/>
</Host>
Third, encrypt website HTTPS
1. Generate key file, enter key password (123456), prompt information can be filled
keytool-genkeypair-alias tomcat-keyalg rsa-keystore/usr/local/tomcat/keystore
Generate key definition alias encryption algorithm key file path
2, edit the configuration file Vim/usr/local/tomcat/conf/server.xml, only need to add the last line to
<connector port= "8443" protocol= "Org.apache.coyote.http11.Http11NioProtocol "
Maxthreads= "sslenabled=" true "scheme=" "https" secure= "true"
Clientauth= "false" sslprotocol= "TLS"
Keystorefile= "Usr/local/tomcat/keystore" keystorepass= "123456"/>//Key file path and password
3, restart the service and verification, remember the port number is 8443
How to use Java+tomcat to create a Web server