Recently, I am trying to build a WEB/AP, API server, and sort it out.
1. WEB (Apache) + AP (Tomcat)
1.1 Installation
1. Install or extract the compressed package to d:\Server\Apache2.2
2. Test: Open the browser, enter localhost:80, and display [It's works!]
1.2 Load-Blancing
1. Tomcat cluster: Install or extract the compressed package to d:\Server\Tomcat1, d:\Server\Tomcat2
2. Download the jk module [mod_jk.so] and put it in: d:\Server\Apache2.2\modules
3. Create a new [d:\Server\Apache2.2\conf\\workers.properties] file
#server worker.list = controller #List of controller names, separated by commas. The web service plugin will initialize it. #========tomcat1 connection command======== # worker.<worker name>.<directive>=<value> worker.tomcat1.port=8009 #ajp protocol port, if two tomcats are deployed in the same server, the ajp port needs to be different worker.tomcat1.host=127.0.0.1 #The ip of the host where tomcat is located, if it is a local machine, just write the ip of the local machine worker.tomcat1.type=ajp13 #worker type, ajp13 is the preferred worker type used by JK for communication between web server and Tomcat worker.tomcat1.lbfactor=1 #Load factor #========tomcat2======== worker.tomcat2.port=9009 worker.tomcat2.host=127.0.0.1 worker.tomcat2.type=ajp13 worker.tomcat2.lbfactor=1 #======== Load Balancing Instructions======== worker.controller.type=lb #worker type, which defines the instructions available for workers. lb for load balancing worker.controller.retries=3 #Number of retries after the request fails worker.controller.balance_workers=tomcat1,tomcat2 #Tomcat name participating in load balancing, worker.controller.sticky_session=false #Whether the session is sticky, false means no sticky, the request of the same session will be processed in different tomcat worker.controller.sticky_session_force=false #When a node jumps, if the value is set to true, the server returns a 500 error to the client, if the value is set to false, it will be forwarded to other tomcats, but the session information will be lost
4. Create a new [d:\Server\Apache2.2\conf\mod_jk.conf] file
JkWorkersFile "D:/Server/Apache2.2/conf/workers.properties" JkMount /* controller jkLogFile "D:/Server/Apache2.2/logs/mod_jk.log"
5. Modify the [d:\Server\Apache2.2\conf\httpd.conf] file
Add the following two lines at the end to load the jk module and configuration
LoadModule jk_module d:/Server/Apache2.2/modules/mod_jk.so Include "d:/Server/Apache2.2/conf/mod_jk.conf"
6) Configure Tomcat
Modify the [D:\Server\tomcat1\conf\server.xml] file, modify the [AJP/1.3]connector, and add jvmRoute (worker name participating in load balancing):
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" jvmRoute="tomcat1"/>
The server.xml in Tomcat2 is also modified, so that the port is not repeated,
<Connector port="9009" protocol="AJP/1.3" redirectPort="8443" jvmRoute="tomcat2"/>
7) Test
Create the same webapp in Tomcat1 and Tomcat2 respectively, and access it through the browser, you will find that Tomcat1 and Tomcat2 are accessed respectively according to the definition of the load factor.
1.3 SSL
1. Modify the [d:\Server\Apache2.2\conf\httpd.conf] file
Uncomment the following two lines
Include conf/extra/httpd-ssl.conf LoadModule ssl_module modules/mod_ssl.so
2. Modify the [d:\Server\Apache2.2\conf\httpd-ssl.conf] file
Modify the file addresses of the certificate field [SSLCertificateFile] and the certificate key field [SSLCertificateKeyFile]
SSLCertificateFile "d:/Server/Apache2.2/conf/server.crt" SSLCertificateKeyFile "d:/Server/Apache2.2/conf/server.key"
(The creation of the certificate is omitted here)
3. Test
Visit https://localhost, and the page will be OK.
4. If you need load balancing, you need to add it to the httpd-ssl.conf file
JkMount /* controller # controller is the controller name
2. API(Tomcat)
2.1 SSL
1. In the server.xml of the Tomcat instance that provides the AP service, add the following content:
<Connector SSLEnabled="true" acceptCount="100" clientAuth="false" disableUploadTimeout="true" enableLookups="false" maxThreads="25" port="8443" keystoreFile="d:\Server\tomcat.keystore" keystorePass="NNNNNN" protocol="org.apache.coyote.http11.Http11NioProtocol" scheme="https" secure="true" sslProtocol="TLS" />
(The generation of tomcat.keystore is omitted here)
Also pay attention to modify the port of the ajp protocol, do not duplicate the port of the ajp protocol in the load balancing Tomcat.
<Connector port="8019" protocol="AJP/1.3" redirectPort="8443" />
2. Test
Visit https://localhost:8443 to see the Tomcat home page.
3.Reference:
1.Apache Tomcat Connectors:
https://tomcat.apache.org/connectors-doc/index.html
2.jk (Tomcat-Apache plugin, used to handle communication between Tomcat and Apache)
https://tomcat.apache.org/connectors-doc-archive/jk2/index.html
3.Tomcat SSL
https://tomcat.apache.org/tomcat-9.0-doc/ssl-howto.html#SSL_and_Tomcat
4. Tomcat cluster
http://www.iteye.com/topic/1017961
5.Apache SSL
http://blog.csdn.net/happyqyt/article/details/9335397
6.Tomcat SSL
http://www.oschina.net/question/12_23148
End