How to separate static and dynamic state by combining Apache with Tomcat

How to separate static and dynamic state by combining Apache with Tomcat

Experimental environment

  • Apache and Tomcat are both installed on the host with IP address 192.168.153.136
  • The host operating system is centos7
  • Before the experiment, turn off the firewall, command: systemctl stop firewalld
  • Disable seliunx, command: setenforce 0
  • The experimental result is that Apache processes html static resources and Tomcat processes jsp dynamic resources

1. Install and start Apache

1.1 Installation

 yum -y install httpd

1.2 Startup

systemctl start httpd

2. Install and start tomcat

2.1 Install JDK

rpm -ivh jdk-8u131-linux-x64_.rpm

2.2 Verify that JDK is installed successfully

[root@host-136 ~]# java -version
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)

2.3 Unzip the Tomcat installation package and move it to the /opt directory

2.3.1 Decompression

tar xzf apache-tomcat-8.5.35.tar.gz

2.3.2 Mobile name change

mv apache-tomcat-8.5.35 /opt/tomcat

2.4 Start the service

/opt/tomcat/bin/startup.sh

3. Install the connector tomcat-connectors source code

3.1 Installation Required Environment

yum -y install httpd-devel gcc gcc-c++

3.2 Decompression

tar zxf tomcat-connectors-1.2.48-src.tar.gz

3.3 Detect environment and configure

cd tomcat-connectors-1.2.48-src/native
./configure --with-apxs=/usr/bin/apxs

3.3 Compile and install

make && make install

3.4 Verify installation is successful

[root@host-136 native]# ll /etc/httpd/modules/mod_jk.so
-rwxr-xr-x. 1 root root 1565864 Jan 6 09:32 /etc/httpd/modules/mod_jk.so

4. Create a test page

4.1 Static Pages

vim /var/www/html/index.html

<h1>static_page_from_apache</h1>

4.2 Dynamic Pages

vim /opt/tomcat/webapps/ROOT/test.jsp

<h1>dynamic_page_from_tomcat</h1>

5. Configure the jk module to integrate Apache with tomcat

5.1 Copy the configuration file

cd tomcat-connectors-1.2.48-src/conf/
cp httpd-jk.conf /etc/httpd/conf.d/
cp workers.properties /etc/httpd/conf/

5.2 Modify the workers.properties configuration file

vim /etc/httpd/conf/workers.properties

5.2.1 Change port to 8009

Note: The Connector AJP Port is used to listen for requests on the AJP (Apache JServ Protocol) protocol. It is usually used to integrate other HTTP servers such as Apache Server. The default value is 8009.

insert image description here

5.2.2 Comment or delete the lines 86 87 88 89 96

insert image description here

5.3 Modify the httpd-jk.conf configuration file

vim /etc/httpd/conf.d/httpd-jk.conf

Remove the comments from line 94 and modify it as follows

insert image description here

6. Restart Apache service

systemctl restart httpd

7. Access page test

7.1 Enter ip/index.html in the browser to test the static page

insert image description here

7.2 Enter ip/test.jsp in the browser to test the dynamic page

insert image description here

This is the end of this article about combining Apache with Tomcat to achieve dynamic and static separation. For more relevant content about combining Apache with Tomcat to achieve dynamic and static separation, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Basic configuration example of Nginx with Apache or Tomcat for dynamic and static separation
  • How to install Apache Tomcat on Ubuntu 16.04
  • A detailed introduction to the differences, connections, and integration between Apache and Tomcat servers
  • Jsp and PHP share port 80 to integrate Apache and Tomcat (no need to add port number when accessing)
  • Apache 2.2 and above versions integrated with Tomcat and implemented load balancing
  • Apache tomcat How to implement multiple domain names for one website

<<:  Some tips on deep optimization to improve website access speed

>>:  Reflection and Proxy in Front-end JavaScript

Recommend

Small program to implement a simple calculator

This article example shares the specific code of ...

Install Docker on Linux (very simple installation method)

I have been quite free recently. I have been doin...

Pricing table implemented with CSS3

Result: Implementation Code html <div id="...

MYSQL string forced conversion method example

Preface Since the types of the same fields in the...

The difference between useEffect and useLayoutEffect in React

Table of contents Prerequisites useEffect commitB...

Remote Desktop Connection between Windows and Linux

When it comes to remote desktop connection to Lin...

Nginx learning how to build a file hotlink protection service example

Preface Everyone knows that many sites now charge...

WeChat Mini Program Basic Tutorial: Use of Echart

Preface Let’s take a look at the final effect fir...

Mobile web screen adaptation (rem)

Preface I recently sorted out my previous notes o...

What are HTML inline elements and block-level elements and their differences

I remember a question the interviewer asked durin...

MySQL paging analysis principle and efficiency improvement

MySQL paging analysis principle and efficiency im...

Detailed explanation of 5 solutions for CSS intermediate adaptive layout

Preface When making a page, we often encounter co...

A brief discussion on mobile terminal adaptation

Preface The writing of front-end code can never e...

In IIS 7.5, HTML supports the include function like SHTML (add module mapping)

When I first started, I found a lot of errors. In...