Configuring HTTPS by APR |
Configuring HTTPS encryption using the APR method has the following steps:
Download OpenSSL from the OpenSSL Web site (http://www.openssl.org/), OpenSSL for Windows can be used on the Windows platform.
Add the bin directory for OpenSSL to your system's PATH environment variable, such as D:\openssl-win64\bin.
3.1 In the development test environment, you need to use OpenSSL to generate a private key, and then create a certificate that uses the private key.
Go to OpenSSL/bin, open a command line window, and enter the following command to create a private key for Tomcat:
openssl genrsa -des3 -out D:\tomcatkey.pem 2048
When prompted for a passphrase, such as "123456", OpenSSL will prompt you to repeat the confirmation. Then a private key named tomcatkey.pem will be generated, with D:\tomcatkey.pem being the path to the private key.
After creating the private key, you also need to create a certificate. Also in the command line window of OpenSSL/bin, execute the following command:
openssl req -new -x509 -key D:\tomcatkey.pem -out D:\tomcatcert.pem -days 1095
When prompted to enter the passphrase for the tomcatkey.pem, in this case "123456" (specified when creating the private key), and enter the relevant information, a self-signed certificate is generated for a period of 3 years (1095 days), that is tomcatcert.pem. tomcatcert.pem uses the private key tomcatkey.pem. D:\tomcatcert.pem is the path of the certificate.
3.2 In the formal production environment, you need to generate the certificate signature request CSR file, and then obtain the official CA signed SSL certificate.
Enter OpenSSL/bin, open the command line, and execute the following command to generate the certificate signing request CSR file:
openssl req -new -nodes -sha256 -newkey rsa:2048 -keyout [$Key_File] -out [$OpenSSL_CSR]
For example:
openssl req -new -nodes -sha256 -newkey rsa:2048 -keyout D:\key.key -out D:\key.csr
Enter the information required to generate the CSR file according to the prompt returned by the system to obtain the CSR file. And then provide to the official CA according to the demand CSR and other relevant information to obtain the SSL certificate signed by the CA. The obtain certificate file compression package is decompressed to obtain a corresponding certificate file (for example, D:/certifile.pfx) and a password file (for example, D:/certifile.txt).
Enter OpenSSL/bin, open the command line, and execute the following commands in turn:
openssl pkcs12 -in D:/certifile.pfx -nodes -out D:/certifile.pem
At this time, OpenSSL will prompt to enter the password of the certificate, which needs to be filled in the password file provided by the official CA (for example: D:/certifile.txt).
openssl rsa -in D:/certifile.pem -out certifile.key
openssl x509 -in D:/certifile.pem -out certifile.crt
a) The following content is found. It is suggested that you comment out the following content and close HTTP:
<Connector port="8090" protocol="HTTP/1.1" relaxedQueryChars="[]|{}" relaxedPathChars="[]|{}" connectionTimeout="8000" redirectPort="8453" executor="tomcatThreadPool" enableLookups="false" URIEncoding="utf-8" compression="on" compressionMinSize="2048" compressableMimeType="text/html,text/xml,text/plain,text/javascript,text/css,application/javascript,application/xml,application/json,application/rjson" />
b) Add the following code after it:
<Connector port="8443" protocol="org.apache.coyote.http11.Http11AprProtocol" SSLEnabled="true" maxThreads="150" scheme="https" secure="true" URIEncoding="utf-8" clientAuth="false" SSLCertificateFile="${user.home}/${SSLCertificateFile}" SSLCertificateKeyFile="${user.home}/${SSLCertificateKeyFile}" SSLPassword="123456" sslProtocol="TLS" sslEnabledProtocols="TLSv1.2"/>
Please note that for 'SSLCancedFile', please fill in the actual absolute path of the certificate file. For example, in the development and testing environment, fill in the generated server certificate information 'D:/tomcatcertificate.pem'; Fill in the real certificate information 'D:/certification.ct' in the actual production environment. Please fill in the actual absolute path of the certificate private key file for 'SSLCaseKeyFile', for example, in the development and testing environment, fill in the generated private key file 'D:/tomcatkey.pem'; Fill in the real private key file in the actual production environment 'D:/Certifiefile.key'. 'SSLPassword' fill in the password for the private key file. If the private key file is not encrypted, this line can be omitted.
<hosts> <host cacheEnabled="true" port="8090" type="webapp" uriBase="/services"> <interface-type>com.supermap.services.wms.WMSServlet</interface-type> <interface-type>com.supermap.services.rest.RestServlet</interface-type> <interface-type>com.supermap.services.handler.HandlerServlet</interface-type> <interface-type>com.supermap.services.wfs.WFSServlet</interface-type> <interface-type>com.supermap.services.wmts.WMTSServlet</interface-type> <interface-type>com.supermap.services.wcs.WCSServlet</interface-type> <interface-type>com.supermap.services.wps.WPSServlet</interface-type> </host> </hosts>
Modify the value of the port parameter in the < host > node to "8443" and add protocolScheme Parameter, the value is "HTTPS", modify as follows:
<hosts> <host cacheEnabled="true" port="8443" protocolScheme="https" type="webapp" uriBase="/services"> <interface-type>com.supermap.services.wms.WMSServlet</interface-type> <interface-type>com.supermap.services.rest.RestServlet</interface-type> <interface-type>com.supermap.services.handler.HandlerServlet</interface-type> <interface-type>com.supermap.services.wfs.WFSServlet</interface-type> <interface-type>com.supermap.services.wmts.WMTSServlet</interface-type> <interface-type>com.supermap.services.wcs.WCSServlet</interface-type> <interface-type>com.supermap.services.wps.WPSServlet</interface-type> </host> </hosts>
<session-config> <session-timeout>30</session-timeout> </session-config>
Add < cookie-config >, modify to:
<session-config> <session-timeout>30</session-timeout> <cookie-config> <http-only>true</http-only> <secure>true</secure> </cookie-config> </session-config>