标签:自己 for files min 掌握 target transport guarantee service
平时做自己的web demo基本上都是用http协议进行访问。
但是正式情况基本上都是https进行访问,所以掌握https的配置是很关键的。
需要准备的材料:
一台可以可以外网访问的远程服务器
tomcat 8.5
java环境(自行百度安装过程和配置环境变量)
web项目war包(可有可无)
在远程服务器上配置好java环境后就是安装tomcat:
详情请见(tomcat安装、配置、使用):https://www.cnblogs.com/longLifeFrog/articles/8612260.html
过程是windows的,但是lunix也大同小异,思路基本一样,可以自行百度搜索相关安装过程
由于我这台远程服务器开了2个端口8080和443。
所以这步要完成用tomcat部署2个不同端口的项目。
先将webapps文件夹和conf文件夹下面的Catalina文件夹,copy一份,如下图所示:
接下来是修改conf/server.xml:
代码如下:
<?xml version="1.0" encoding="UTF-8"?> <Server port="8005" shutdown="SHUTDOWN"> <Listener className="org.apache.catalina.startup.VersionLoggerListener" /> <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" /> <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" /> <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" /> <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" /> <GlobalNamingResources> <Resource name="UserDatabase" auth="Container" type="org.apache.catalina.UserDatabase" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" pathname="conf/tomcat-users.xml" /> </GlobalNamingResources> <Service name="Catalina"> <!--http配置--> <Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" /> <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> <Engine name="Catalina" defaultHost="localhost"> <Realm className="org.apache.catalina.realm.LockOutRealm"> <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/> </Realm> <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="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> </Service> <Service name="Catalina2"> <Connector port="443" protocol="HTTP/1.1" connectionTimeout="20000" maxThreads="150" redirectPort="8443" SSLEnabled="true" scheme="https" secure="true" clientAuth="false" sslProtocol="TLS" keystoreFile="C:\Program Files\Apache Software Foundation\Tomcat 8.5\www.xxxx.com.jks" keystorePass="xxxxxx" /> <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> <Engine name="Catalina2" defaultHost="localhost"> <Realm className="org.apache.catalina.realm.LockOutRealm"> <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/> </Realm> <Host name="localhost" appBase="webapps2" unpackWARs="true" autoDeploy="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> </Service> </Server>
上图中8080端口是http形式,如果要将其改成https可以参考443端口的配置。
上图中www.xxxx.com.jks是从权威机构拿到的证书,keystorePass填相应的密码。
第三步:
copy项目到webapps和webapps2,然后运行startup,访问。这样就成功了。
补充:
1、http自动跳转https的安全配置:
到conf目录下的web.xml。在 </welcome-file-list>后面, </web-app>之前,也就是倒数第二段里,加上这样一段:
<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>
结果如下图所示:
这步目的是让非ssl的connector跳转到ssl的connector去。所以还需要前往server.xml进行配置:
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="443" />
redirectPort改成ssl的connector的端口443,重启tomcat后便会生效。
以上是权威证书的https配置方法。
标签:自己 for files min 掌握 target transport guarantee service
原文地址:https://www.cnblogs.com/longLifeFrog/p/9067147.html