配置server.xml
文件
域名访问先修改成80端口,然后是redirectPort为443
<Connector port="80" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="443" />
配置SSL证书
<Connector port="443" protocol="org.apache.coyote.http11.Http11NioProtocol" maxThreads="150" SSLEnabled="true" URIEncoding="UTF-8" defaultSSLHostConfigName="www.site1.com"> <!--配置证书路径,密码--> <SSLHostConfig hostName="www.site1.com" caCertificateFile="cert/www.site1.com.pem"> <Certificate certificateKeystoreFile="cert/www.site1.com.pfx" certificateKeystoreType="PKCS12" certificateKeystorePassword="***" /> </SSLHostConfig> <SSLHostConfig hostName="www.site2.com" caCertificateFile="cert/www.site2.com.pem"> <Certificate certificateKeystoreFile="cert/www.site2.com.pfx" certificateKeystoreType="PKCS12" certificateKeystorePassword="***" /> </SSLHostConfig> </Connector>
修改redirectPort为443
<!-- Define an AJP 1.3 Connector on port 8009 --> <Connector port="8009" protocol="AJP/1.3" redirectPort="443" />
一个项目对应多个域名
<Host name="www.site1.com" appBase="webapps" unpackWARs="false" autoDeploy="true" defaultHost="www.site1.com"> <!--多个域名别名--> <Alias>www.site1.com</Alias> <Alias>www.site2.com</Alias> <!--默认项目访问路径--> <Context path="" docBase="project" reloadable="false" /> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log" suffix=".txt" pattern="%h %l %u %t "%r" %s %b" /> </Host>
多个项目需要配置多个host,其中需要注意每个host下默认项目访问路径
<Engine name="Catalina" defaultHost="www.site1.com"> <Host name="www.site1.com" appBase="webapps" unpackWARs="true" autoDeploy="true"> <!--默认项目访问路径--> <Context path="" docBase="project1" reloadable="true" /> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log" suffix=".txt" pattern="%h %l %u %t "%r" %s %b" /> </Host> <Host name="www.site2.com" appBase="myapps" unpackWARs="true" autoDeploy="true"> <!--默认项目访问路径--> <Context path="" docBase="project2" reloadable="true" /> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log" suffix=".txt" pattern="%h %l %u %t "%r" %s %b" /> </Host> </Engine>