tomcat配置域名及HTTPS

1.安装JDK及Tomcat

tar xf jdk-8u201-linux-x64.tar.gz -C /usr/local/
cd /usr/local/
ln -sv jdk1.8.0_201/ java
vim  /etc/profile.d/java.sh
export JAVA_HOME=/usr/local/java
export CLASSPATH=$JAVA_HOME/lib/tools.jar
export PATH=$JAVA_HOME/bin:$PATH

. /etc/profile.d/java.sh
java -version


tar xf apache-tomcat-8.5.57.tar.gz -C /usr/local/
cd /usr/local/
ln -sv apache-tomcat-8.5.57/ tomcat
cd tomcat

2.配置Tomcat使用域名

编辑server.xml文件

<Engine name="Catalina" defaultHost="www.inktech.ltd"> #设置默认域名,类似Nginx default server,接收所有发往非明确定义虚拟主机的请求
<Host name="www.inktech.ltd"  appBase="webapps"  #name 配置的域名 appBase 加载的文件夹,默认即可
            unpackWARs="true" autoDeploy="true">
            <Alias>inktech.ltd</Alias> #如果项目有多个域名可以在Alias添加,此处是将域名默认跳转到www上
#path 输入的URI,为空为不输入,不可省略 docBase 项目代码目录 reloadable 动态加载,生产环境建议禁用 <!-- Context path="" docBase="C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\qxw" debug="0" reloadable="true" ></Context> -->

3.添加HTTPS证书

mkdir cert
cd cert
mv ~/8350448_inktech.ltd_tomcat.zip .        #证书从供应商处下载
unzip 8350448_inktech.ltd_tomcat.zip
cat pfx-password.txt  #查看证书密码
keytool -changealias -keystore /usr/local/tomcat/cert/inktech.ltd.pfx -alias alias  -destalias tomcat #修改证书别名,默认alias
输入密钥库口令:   #password文件内容

4.设置HTTPS

    <Connector port="8080" protocol="HTTP/1.1"  #建议80
               connectionTimeout="20000"
               redirectPort="8443" />  #此端口和下面的保持一致
    <Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol"  
               maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
               clientAuth="false" sslProtocol="TLS" keyAlias="tomcat"  URIEncoding="UTF-8"  
               keystoreFile="/usr/local/tomcat/cert/inktech.ltd.pfx"    #刚刚解压的证书
               keystorePass="ddxfexc7"   #密码文件内容
               ciphers="TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, 
                TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
                TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384,
                TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
                TLS_ECDHE_RSA_WITH_RC4_128_SHA,
                TLS_RSA_WITH_AES_128_CBC_SHA256,
                TLS_RSA_WITH_AES_128_CBC_SHA,
                TLS_RSA_WITH_AES_256_CBC_SHA256,
                TLS_RSA_WITH_AES_256_CBC_SHA,
                SSL_RSA_WITH_RC4_128_SHA"/>

5.设置HTTPS强制跳转

编辑web.xml,在最后添加一下内容

<login-config>
      <!-- Authorization setting for SSL -->
        <auth-method>CLIENT-CERT</auth-method>
        <realm-name>Client Cert Users-only Area</realm-name>
    </login-config>

    <security-constraint>
      <!-- Authorization setting for SSL -->
        <web-resource-collection >
            <web-resource-name >SSL</web-resource-name>
            <url-pattern>/*</url-pattern>
        </web-resource-collection>
        <user-data-constraint>
            <transport-guarantee>CONFIDENTIAL</transport-guarantee>
        </user-data-constraint>
    </security-constraint>

6.启动并验证

做好DNS或hosts解析

访问http://www.inktech.ltd:8080/

 验证上是否会自动跳转到https://www.inktech.ltd:8443/

 

 

 

posted @ 2023-05-29 11:35  百衲本  阅读(1121)  评论(0编辑  收藏  举报
cnblogs_post_body { color: black; font: 0.875em/1.5em "微软雅黑" , "PTSans" , "Arial" ,sans-serif; font-size: 15px; } cnblogs_post_body h1 { text-align:center; background: #333366; border-radius: 6px 6px 6px 6px; box-shadow: 0 0 0 1px #5F5A4B, 1px 1px 6px 1px rgba(10, 10, 0, 0.5); color: #FFFFFF; font-family: "微软雅黑" , "宋体" , "黑体" ,Arial; font-size: 23px; font-weight: bold; height: 25px; line-height: 25px; margin: 18px 0 !important; padding: 8px 0 5px 5px; text-shadow: 2px 2px 3px #222222; } cnblogs_post_body h2 { text-align:center; background: #006699; border-radius: 6px 6px 6px 6px; box-shadow: 0 0 0 1px #5F5A4B, 1px 1px 6px 1px rgba(10, 10, 0, 0.5); color: #FFFFFF; font-family: "微软雅黑" , "宋体" , "黑体" ,Arial; font-size: 20px; font-weight: bold; height: 25px; line-height: 25px; margin: 18px 0 !important; padding: 8px 0 5px 5px; text-shadow: 2px 2px 3px #222222; } cnblogs_post_body h3 { background: #2B6695; border-radius: 6px 6px 6px 6px; box-shadow: 0 0 0 1px #5F5A4B, 1px 1px 6px 1px rgba(10, 10, 0, 0.5); color: #FFFFFF; font-family: "微软雅黑" , "宋体" , "黑体" ,Arial; font-size: 18px; font-weight: bold; height: 25px; line-height: 25px; margin: 18px 0 !important; padding: 8px 0 5px 5px; text-shadow: 2px 2px 3px #222222; } 回到顶部 博客侧边栏 回到顶部 页首代码 回到顶部 页脚代码