Win7 apache2.2+tomcat7.0 Integrated configuration detailed _win server

Source: Internet
Author: User
Tags builtin custom name web hosting server port apache tomcat

A brief introduction of Apache, Tomcat

Apache HTTP Server (Apache), an open source Web server for the Apache Software Fund Association, is one of the most popular Web server software to run on operating systems such as Windows, Unix, and Linux. The Apache response is fast and efficient, but only static pages such as HTML are supported (PHP pages can also be supported after loading plug-ins).
Apache Tomcat is a Web server developed jointly by the Apache Software Fund Association and Sun Corporation, which supports JSP, Servlet, and other static pages, such as HTML.
In the same operating environment, the response speed of Tomcat to static pages without Apache sensitivity, integrated Apache and Tomcat can make the system run in a good environment, improve system efficiency.

Second, package download

Operating Environment: Windows 7

Apache 2.2 Download: http://httpd.apache.org/download.cgi

Tomcat 7.0 Download: http://tomcat.apache.org/download-70.cgi

JDK 6 Download: http://www.oracle.com/technetwork/java/javase/downloads/index.html

Mod_jk.mo Connection Pack Download: http://apache.etoak.com//tomcat/tomcat-connectors/jk/binaries/windows/

Third, JDK installation

The JDK (Java Development Kit) is the Sun's product for Java developers and is the most widely used Java SDK today. The JDK is the core of the entire Java system, including the Java Runtime environment and the underlying class library. Common versions include JDK 6, JDK 7, JDK 8.

After you successfully install JDK 6, you must set the environment variables to allow the system to perceive and invoke JDK 6.

Open the Control Panel--> system security--> System--> advanced system settings--> environment variable, add the following configuration:

Variable Value Description
Java_home C:\ jdk1.6.0_30 Write path to JDK installation
Path ;%java_home%\bin Add this value to the path's original value
Classpath ;%java_home%\lib\dt.jar;%java_home%\lib\tools.jar Add this value to the original value of the Classpath

Four, Apache 2.2 installation

To run the Apache 2.2 installation package, you can set the domain name, server name, and port in the setup process, and the default port for Apache is 80.

The specific installation steps can refer to this article: http://www.jb51.net/article/52086.htm

Httpd.conf is the main Apache configuration file, after the Apache installation is complete, you can try to open the "/apache 2.2/conf/httpd.conf" file for modification, the following is the common configuration of Apache:

ServerRoot "C:/Program Files/apache Software foundation/apache2.2" # defines the root directory for configuration files, log files, and so on, usually for Apache2.2 installed directories <ifmodule  Mpm_winnt.c> threadsperchild maxrequestsperchild 0 </IfModule> # <ifmodule prefork.c> # ... </IfModule> # <ifmodule worker.c> # ... # </IfModule> # Apache supports MPM multiplexing module, MPM is a hybrid pattern of multiple processes and multithreading # A Pache defines perwork, worker, BeOS, and many other modes for Unix, OS/2, and BeOS systems # but only supports Winnt mode # in Windows Threadperchild defines the number of commonly used threads,

Maxrequestsperchild defines the maximum number of threads Listen 8000 # Set Apache listening path, generally default to 127.0.0.1:80 port, but because 80 is often occupied by processes such as IIS, # Build to another port, use 8000 ports here LoadModule actions_module modules/mod_actions.so LoadModule alias_module modules/mod_alias.so LoadModule asis_module modules/mod_asis.so LoadModule auth_basic_module modules/mod_auth_basic.so # LoadModule Auth_digest_module Mod_auth_digest.so .... # set up the module to handle <ifmodule!mpm_netware_module> <ifmodule!mpm_winnt_module&----
     Gt User Daemon Group Daemon </IfModule>
</IfModule> # If you want to make httpd run as a different user or group, you must start at the beginning with a root and then switch it to the user or group you want to use.

ServerAdmin leslies2@163.com # Defines the admin mailbox and sends the error message to this address when Apache goes wrong ServerName 127.0.0.1 # If your host does not have a DNS name registered, type its IP address here DocumentRoot "E:/apache Webs" # defines the root directory of the publishing file <directory/> Order deny,allow deny </Directory> # for Special A set of directories configures a set of default directives that prohibit access to the root directory <directory "E:/apache webs/website1"/> Order deny,allow </Directory> # Allow clients to access WEBSI
Te1 directory ErrorLog "Logs/error.log" # ErrorLog: Error log file positioning.
LogLevel Warn # LogLevel: Controls the number of log messages recorded in the error log file.

# includes: Debug,info,notice,warn,error,crit,alert,emerg.
  <ifmodule log_config_module> Logformat "%h%l%u%t \%r\"%>s%b \ "%{referer}i\" \ "%{user-agent}i\" "combined Logformat "%h%l%u%t \%r\"%>s%b "common <ifmodule logio_module> Logformat"%h%l%u%t \ "%r\"%>s %b \ "%{referer}i\" \ "%{user-agent}i\"%I%o "Combinedio </IfModule> customlog" Logs/access.log "common Dule> # Log Access format settings <ifmodule alias_mOdule> scriptalias/cgi-bin/"C:/Program files/apache Software foundation/apache2.2/cgi-bin/" </IfModule> set Default CGI script directory and alias <directory "C:/Program files/apache Software foundation/apache2.2/cgi-bin" > allowoverride None Opt Ions None order Allow,deny allow </Directory> # Set default CGI script directory properties defaulttype text/plain # Set default MIME content type & Lt;ifmodule mime_module> typesconfig conf/mime.types addtype application/x-compress. Z AddType application/x-gzip. gz. tgz </IfModule> # Specify MIME type mapping file <ifmodule ssl_module> sslrandomseed star Tup builtin Sslrandomseed connect builtin </IfModule> # SSL default configuration

When the configuration is complete, start Apache 2.2 and add a static page index.html to "E:\\apache webs\website1".
Finally, open http://localhost:8000/index.html to test whether Apache 2.2 is working correctly.

Five, Tomcat 7 installation

Run the Tomcat 7 installation package, after the installation, open the Control Panel--> system security--> System--> advanced system settings--> environment variable, add the following configuration:

Variable Value
Tomcat_home C:\Program Files\apache Software Foundation\tomcat 7.0
Path ;%tomcat_home%\lib;%tomcat_home%\lib\servlet-api.jar;%tomcat_home%\lib\jsp-api.jar

In Tomcat's directory, the Conf folder contains Tomcat's core configuration, the Logs folder contains Tomcat logging, and the WebApps folder is the default Web hosting directory for Tomcat.

The Server.xml in the Conf folder is the most important configuration for Tomcat, and the following are common settings for Server.xml:

<?xml version= ' 1.0 ' encoding= ' utf-8 '?> <!--Server Property Description Port: Specifies a port that listens for requests to shut down Tomcat shutdown: to the top Shut down the server's command string--> <server port= "8006" shutdown= "Shutdown" > <!--define multiple listening--> <listener classname= "Org.apache.catalina.core.AprLifecycleListener" sslengine= "on"/> <listener classname= " Org.apache.catalina.core.JasperListener "/> <listener classname=" Org.apache.catalina.core.JreMemoryLeakPreventionListener "/> <listener classname=" Org.apache.catalina.mbeans.GlobalResourcesLifecycleListener "/> <listener classname=" Org.apache.catalina.core.ThreadLocalLeakPreventionListener "/> <!--define shared resources--> <globalnamingresources > <resource name= "userdatabase" auth= "Container" type= "Org.apache.catalina.UserDatabase" descript
        ion= "User database" can be updated and saved "factory=" Org.apache.catalina.users.MemoryUserDatabaseFactory "
 Pathname= "Conf/tomcat-users.xml"/> </GlobalNamingResources> <!--<Service> elements are defined by the Org.apache.catalina.Service interface, which contains a <Engine> element, And one or more <connector&gt, these Connector elements are shared with the same engine element--> <service name= "Catalina" > <!--<connector > element represents the exchange of information with the client, which can receive the customer's request and return the response result to the customer--> <!--define how the HTTP protocol is handled, and the processing interface defaults to 8080 because this interface is often invoked by other applications, it is recommended that you modify the interface--> & Lt Connector port= "8081" protocol= "http/1.1" connectiontimeout= "20000" redirectport= "8443"/> <!--definition ajp/1.3 protocol processing, this is the integration of Tomcat+apache core protocol, please carefully handle--> <connector port= "8009" protocol= "ajp/1.3" redirectport= "8443" 
     /> <!--Each <Service> element can include only one <Engine> element. <Engine> element processing customer requests received by all <Connector> elements in the same <Service>--> <engine name= "Catalina" defaulthost= "localhost" > <!--realm is a "database" username that stores user names, passwords, and roles associated with user names, and passwords can be used to verify the validity of a user to one or more Web applications. --> <realm classname= "Org.apache.catalina.realm.LockOutRealm" > <realm classname= "org.apache.catalIna.realm.UserDatabaseRealm "resourcename=" Userdatabase "/> </Realm> <!--<Host> element defines a virtual master
     Machine, which can contain one or more Web applications-->  

Tomcat uses port 8080 to process HTTP requests by default (because this port is often invoked by other applications and is recommended for modification).
When you have finished setting up, you can see the Tomcat administration page by entering address localhost:8080.

You can create a new index.jsp page in the WebApps directory, start Tomcat, and test whether Tomcat is working correctly.

Vi. Integration of Apache+tomcat

In the case of Apache and Tomcat running, copy Mod_jk.mo to "/apache2.2/modules"
Add the Workers.properties file under the/tomcat 7.0/conf folder and enter the following.

Workers.tomcat_home=c:\program files\apache Software foundation\tomcat 7.0
#让 mod_jk module senses Tomcat
Workers.java _home=c:\program files\java\jdk1.6.0_30\jre
#让 mod_jk module perceives JRE
ps=\
#指定文件路径分割符
worker.list=config1
worker.config1.port=8009
#工作端口, this port should match
the port used by the ajp/1.3 protocol for connector elements in Server.xml Worker.config1.host=localhost
#Tomcat服务器的地址
worker.config1.type=ajp13
#类型
Worker.config1.lbfactor=1
#负载平衡因数

Attention:

WORKER.LIST=CONFIG1, CONIFG1 is a custom name, but this name must match the name of the Jkmount directive in the "/apache 2.2/conf/httpd.conf" file described below.

After adding the Workers.properties file, you can modify the "/apache 2.2/conf/httpd.conf" file and add the following configuration.
Note that the variable in the Jkmount directive must be the same as the name configured by Worker.list.

# Set up the virtual host, define the port as 8000 <virtualhost 127.0.0.1:8000> ServerName 127.0.0.1 #定义服务名称 documentroot "C:/Program Fil Es/apache Software foundation/tomcat 7.0/webapps "#定义站点项目所在路径, point the path to the default Web site directory in Tomcat directoryindex index.html index. HTM index.jsp ErrorLog logs/shsc-error_log.txt customlog logs/shsc-access_log.txt Common #例子1, allowing Apache support for WebApps /sun.shop/blog page Transfer jkmount/sun.shop/blog/* config1 #例子2, when the Apache request this folder page, the system will be turned to Tomcat parsing Jkmount/*.jsp Config 1 #例子3, to Apache request JSP page, with Tomcat parsing Jkmount/*.do config1 #例子4, to the Apache request. Do action with Tomcat parsing Jkmount/* Action Config1 #例子5 to ask Apache for the. Action action, use Tomcat to parse </VirtualHost> # allow clients to access this path <directory "C:/PR 
   Ogram files/apache Software foundation/tomcat 7.0/webapps "> Options Indexes followsymlinks allowoverride None Order Allow,deny allow from all </Directory> LoadModule jk_module modules/mod_jk.so # here mod_jk.so file as You downloaded the file Jkworkersfile "C:/program files/apache Software foundation/tomcat 7.0/conf/workers.properties "# Specify TOMCAT Listener profile address Jklogfile" c:/ Program Files/apache Software foundation/tomcat 7.0/logs/mod_jk2.log "# Specify log storage location Jkloglevel info

Attention:

The Jkmount/*.jsp config1 directive means that when a client sends a *.JSP page request to Apache, the handle is directed to Tomcat. When using struts, it is recommended to use the *.action, *.do, and other suffix naming action, otherwise, if you use the prefix name, add jkmount/* CONFIG1 command, Apache will include the *.html and other static page all requests, turn to Tomcat.

When the above configuration is complete, restart Apache, Tomcat. At this point Apache, Tomcat's default directory is "C:/Program files/apache Software foundation/tomcat 7.0/webapps", for HTTP requests, Apache uses 8000 ports, Tomcat uses port 8081. After adding the index.jsp page to the default directory, send the http://localhost:8000/index.jsp page request directly to Apache, which shows that Apache will turn the request to Tomcat for processing.
Java development is interested in friends Welcome to join the QQ group: 174850571 Common discussion!

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.