Integration of Apache and tomcat in Windows

Source: Internet
Author: User
Tags website server

Apache httpd is a popular website server software. It is not only powerful, but also free of charge and supports a variety of popular operating systems (Windows, Linux, and Mac OS) on the market ). At the same time, tomcat, which is also produced by Apache, is usually used for Java Servlet/jsp support.
In addition to supporting Java Servlet/JSP, Tomcat can also be used as a website server. However, it is less efficient to parse static html files and image files than Apache httpd. If the server that uses tomcat has a large Website access volume, the system resource usage will increase significantly. Recently, When I encountered this problem during project implementation, I also thought of using Tomcat + Apache services at the same time. Apache processes static resources, Tomcat processes dynamic resources such as JSP and Java Servlet. I have read a lot of posts about Apache and tomcat integration on the Internet. Most of them share posts with each other. There are several key issues that are not clearly explained, and most of themArticleThe software versions mentioned in the explanation are outdated. Therefore, I have summarized my practical experience and hope to help you.

Preparations:
The installation sequence of the software can be adjusted as appropriate, but JRE (JDK) must be installed before Tomcat:
1. Install JRE (JDK)
Select the default installation option. (After the JDK of the old version is installed, you must set the system environment variables. It does not matter if JRE and JDK 1.5.0 are not set .) After the installation is complete, you can choose to set your system environment variables as follows: My computer-> right-click Properties-> General-> advanced-> Environment Variables
Java_home = D: \ Java \ jre1.5.0 _ 06
Classpath =.; D: \ Java \ jre1.5.0 _ 06 \ Lib \ DT. jar; D: \ Java \ jre1.5.0 _ 06 \ Lib \ tools. Jar
Path = D: \ Java \ jre1.5.0 _ 06 \ bin
Note that the file path should be changed to the actual installation path.

2. install Apache
Note that if your local machine has already installed IIS and uses port 80, you must first stop or disable IIS in the service. Install the software by default. Set the network domain and server name to localhost during the installation process and set your email address. below, you will choose only for the current user or for all users. The default value is for all users. In this way, Apache occupies port 80 and runs as a system service.
After the installation is complete, enter http: // localhost in the browser and you will see the successful Apache page. the main directory of Apache is D: \ apache \ apache2. Apache is running. You can view its icon on the tray of the window and double-click it, in the displayed window, select "Open Apache monitor", click STOP to stop the apaceh service, because Tomcat and JK are to be installed below.

3. tomcat installation
Select "D: \ Tomcat" as the installation directory, and enter "http: // localhost: 8080" in the browser after the installation is successful. The "Tomcat" page indicates that the installation is successful. There have been many detailed articles on Tomcat settings, so I will not detail them here.

4. JK Installation
Copy mod_jk_2.0.55.so to D: \ apache \ apache2 \ modules. different Tomcat maps to different JK file extensions, which may be *. DLL, or *. so, download the appropriate JK version based on your tomcat version.

After the installation is complete, open the CMD command prompt and run D: \ apache \ apache2 \ bin \ httpd.exe-T. You will see "syntax OK", indicating that Apache configuration is normal. this command is very useful and will be used again when you continue to configure Apache.

Configuration server:

1. Configure Tomcat
Search for the conf/workers. properties file in the directory and compare the text content below. If the following content is different, modify it.
Workers. tomcat_home = D: \ Tomcat # Let the mod_jk module know the location of Tomcat
Workers. java_home = D: \ Java \ jre1.5.0 _ 06 # Let the mod_jk module know the location of the JRE
PS = \
Worker. List = ajp13 # module version
# Worker. ajp13.port = 8009 # Working port. Do not modify it if it is not occupied
Worker. ajp13.host = localhost # local machine. If the above Apache host is not localhost, modify it accordingly.
Worker. ajp13.type = ajp13 # type
Worker. ajp13.lbfactor = 1 # Number of proxies, no need to modify

If the file does not exist, it is created. And fill in the above content.

2. Configure Apache
Open httpd. conf under D: \ apache \ apache2 \ conf, and add the following section at the end.CodeAnd save.
# Set the connection between APACHE and tomcat. When apache encounters a JSP file, it is handed over to tomcat in the background for processing.
Loadmodule jk_module modules/mod_jk_2.0.55.so
# The mod_jk file here is the file you downloaded
Jkworkersfile "D:/tomcat/CONF/workers. properties"
# Specify the Tomcat Listener Configuration File address
Jklogfile "D:/tomcat/logs/mod_jk2.log"
# Specify the log storage location
Jkloglevel info

# Setting up a VM
<Virtualhost localhost>
Serveradmin localhost
DocumentRoot D:/test1
# The path of your site project should be the same as the directory settings in Tomcat
Servername localhost
Directoryindex index.html index.htm index. jsp
Errorlog logs/shsc-error_log.txt
Customlog logs/shsc-access_log.txt common
Jkmount/servlet/* ajp13
# Apache supports servlet transfer for Tomcat Parsing
Jkmount/*. jsp ajp13
# Apache supports JSP transmission for Tomcat Parsing
Jkmount/*. Do ajp13
# Apache supports. Do transmission for Tomcat Parsing
</Virtualhost>

# Action comments that start with can be deleted. The configuration here is to configure the site by setting the virtual directory, re-specifying the servername and DocumentRoot paths. In fact, Apache configuration can be very flexible, or you can choose not to use the virtual directory, directly modify the default configuration of the site, use any text editing tool to search for items such as servername, DocumentRoot, and serveradmin, and then modify the configuration according to your actual situation. I suggest you try different configurations. This is a pleasant experience.
After all the modifications are completed, Run D: \ apache \ apache2 \ bin \ httpd.exe-t again. If "syntax OK" is displayed, all your configurations are correct, double-click the icon in the tray of the window, and then click start to run.
Enter http: // localhost/in the address bar, respectively. If the result is the same as http: // localhost: 8080/, Apache and tomcat are integrated successfully.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.