Use Apache + Tomcat to create and manage Web Servers

Source: Internet
Author: User
Tags http authentication
Article Title: Use Apache + Tomcat to create and manage Web servers. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
Apache is simple, fast, and stable, and can be used as a proxy server. Originally, it was used only for small or experimental Internet networks, and was gradually expanded to various Unix systems, especially for Linux. Apache has multiple products that support SSL technology and multiple virtual hosts. Apache is a process-based structure. Processes consume more system expenses than threads and are not suitable for multi-processor environments. Therefore, when an Apache Web site is expanded, it is usually to add servers or expand cluster nodes, rather than adding processors. The success of Apache mainly lies in its open source code, an open development team, and support for cross-platform applications (which can run on almost all Unix, Windows, and Linux platforms) and its portability.
  
Apache is installed as the default configuration in almost all Linux releases. SuSE7.1 or even pre-installed Apache with various advanced module options, such as PHP3, mod_perl, and LDAP. Users will be surprised to find that a powerful Web server is available after the system is successfully installed. Although installing Apache is not very simple, it is worthwhile to download the source code package and compile the new Apache if Apache with new features or security patches is released.
  
Apache not only has a large user base, but also has a wide range of Configuration documentation. Apache provides server-side support for script technology, such as Perl and PHP. Apache can use Apache JServ to support Java servlets and JSP. Many modules of Apache implement security protection: for example, mod_auth provides proper protection for data on the server, while the SSL module is used to protect the communication security between the server and the client.
  
Next we will introduce the Tomcat server software. Tomcat is a JSPServer developed by Sun and Apache. It supports versions such as Servlet2.2 and JSP1.1. I suggest you use Tomcat, and Tomcat will replace JServ in the future and become the main Servlet & JSPEngine of Apache. Tomcat is designed to run on an independent Server. Unlike Jserv, which is attached to Apache, Tomcat can be used in servlet rather than HttpServlet. Tomcat is a Java program, so it can be used as long as JDK is available. You do not need to consider the operating system platform.
  
The Tomcat server expanded as a WEB server has some problems to address:
  
Tomcat is not as fast as Apache when processing static pages.
Tomcat is not configurable Like Apache.
Tomcat is not as strong as Apache.
  
For the above reasons, a real website uses an Apache server as the Web server to provide services for static page requests of the website, and Tomcat server as a Servlet/JSP plug-in, displays the dynamic page of the website.
  
Only by adopting a structure such as apache-> tomcat has more special advantages, mainly reflected in better scalability and security. The main feature of this type of site is that every page may be dynamically generated, but the main part of the data is static (for example, all kinds of images GIF, JPG, PNG, streaming Media). This structure has the advantages of both scalability and security.
  
The following uses solairs8 as an example. Download Apache1.3.27 and Tomcat4.1.12 of Solaris free of charge to describe how to install and configure the WEB service software apache and the application service software tomcat (including JDK.
  
Note: The versions of Apache and Tomcat downloaded are related to the operating system type.
  
   I. Application Environment
The operating system is Solaris8, the application environment is Java1.3 (assuming it is installed in the/usr/java1.3 directory), and perl5.6 (assuming it is installed in the/usr/local/bin directory) and gzip (assuming it is installed in the/usr/local/bin directory ).
  
   Ii. Download, compile and install software packages
1,
  
You can download the apachesource code package apache_1.3.27.tar.gz in the http://www.apache.org.
In.
In.
  
2. Compilation and Installation
  
If the software packages have been downloaded to a working directory (for example,/home/tmp), Apache and Tomcat will be installed in the/home directory. In the current directory, we can perform the following operations.
  
1) Compile and install the Apache Application Service
  
① Unpack
  
$/Usr/local/bin/gzip-dc./apache_1.3.27.tar.gz | tarxf-
  
② Compile
  
$ Cd apache_1.3.27
$./Configure -- prefix =/home/apache-1.3.27.
-- With-perl =/usr/local/bin/perl -- enable-module = so
  
Assume that the perl Command is installed in the/usr/local/bin directory, and the Apache service is installed in the/home/apache-1.3.27 directory.
  
$ Make
  
③ Installation
  
$ Su
# Make install
  
2) Compile and install the mod_jk plug-in
  
① Unpack
  
$/Usr/local/bin/gzip-dcjakarta-tomcat-4.1.12-src.tar.gz | tarxf-
  
② Compile
  
$ Cd jakarta-tomcat-4.1.12-src/src/native/apache1.3
$/Home/apache-1.3.27/bin/apxs-omod_jk.so-D SOLARIS-I ../jk-I/
Usr/java1.3/include-I/usr/java1.3/include/solaris-lposix4-c *. c ../jk/*. c
  
Assume that Java is installed in the/usr/java1.3 directory.
  
③ Installation
  
$ Su
#/Home/apache-1.3.27/bin/apxs-I-a-njkmod_jk.so
Cp mod_jk.so/home/apache-1.3.27/libexec/mod_jk.so
Chmod 755/home/apache-1.3.27/libexec/mod_jk.so
[Activating module 'jkin/home/apache-1.3.27/conf/httpd. conf]
  
3) install the Tomcat Service
  
Decompress the compiled Tomcat 4.1.12 package to the/home directory.
  
$ Su
#/Usr/local/bin/gzip-dcjakarta-tomcat-4.1.12.tar.gz | (cd/home; tarxf -)
  
3. parameter configuration
  
(1) configure the Apache service
  
Run the vi command to open the configuration file httpd. conf of Apache.
  
# Cd/home/apache-1.3.27/conf
# Vi httpd. conf
  
Add the following content at the end.
  
JkWorkersFile/home/jakarta-tomcat-4.1.12/conf/workers. properties
JkLogFile/home/apache-1.3.27/logs/mod_jk.log
  
Note: The log file can be adjusted as needed.
  
JkLogLevelwarn
JkMount/*. jspajp13
JkMount/servlet/*. jspajp13
  
(2) configure the Tomcat Service
  
First, modify the server. xml file.
  
Assume that the root directory of the Web page that stores Apache is/home/htdocs.
  
# Cd/home/jakarta-tomcat-4.1.12/conf
# Vi server. xml
  
Then, embed the following content in the Connectors section.
  
<ConnectorclassName = "org. apache. tomcat. service.
PoolTcpConnector "> <Parametername =" handler"
Value = "org. apache. tomcat. service. connector. Ajp
13 ConnectionHandler "/>
<Parametername = "port" value = "8007"/>
</Connector>
  
Then, embed the following content in the SpecialWebapps section.
  
<Contextpath = ""
DocBase = "/home/htdocs"
Debug = "0">
</Context>
  
Modify the workers. properties file.
  
# Vi workers. properties
...
Workers. tomcat_home =/home/jakarta-tomcat-4.1.12
...
Workers. java_home =/usr/java1.3
...
Ps =/
...
  
Then modify Tomcat to start and close the command file.
  
# Cd ../bin
# Vi startup. sh
  
Embed the following content before the "BASEDIR = 'dirname $ 0'" statement.
  
PATH =/usr/java1.3/bin: $ PATH :.
JAVA_HOME =/usr/java1.3
TOMCAT_HOME =/home/jakarta-tomcat-4.1.12
Export PATH JAVA_HOMETOMCAT_HOME
# Vi shutdown. sh
  
Finally, embed the following content before the "BASEDIR = 'dirname $ 0'" statement.
  
PATH =/usr/java1.3/bin: $ PATH :.
JAVA_HOME =/usr/java1.3
TOMCAT_HOME =/home/jakarta-tomcat-4.1.12
Export PATH JAVA_HOMETOMCAT_HOME
  
So far, Apache and Tomcat server software has been installed successfully. The above is the basic configuration for building a JSP website on the UNIX (Solaris) platform. Apache and Tomcat support JSP dynamic web pages through a plug-in named "mod_jserv". Using this Apache/Jserv method to configure parameters is complex and the running efficiency is low, the support for SSL (an encrypted transmission mode) is not ideal. Therefore, the Jakarta Working Group recently developed the "mod_jk" plug-in, which makes up for the shortcomings of mod_jserv, it also supports a variety of Web services other than Apache. For more information about the implementation principles of this Apache/Jk method, see.
  
   Iii. Web server security management and maintenance in UNIX or LIUNX Environment
1. Start and close Apache and Tomcat
#/Home/apache-1.3.27/bin/apachectl start
#/Home/apache-1.3.27/bin/apachectl stop close
#/Home/jakarta-tomcat-4.1.12/bin/startup sh start
#/Home/jakarta-tomcat-4.1.12/bin/shutdown sh close
  
2. Security Management of Apache and Tomcat web servers
  
1) Both Apache and Tomcat support the Secure Socket Layer (SSL) function.
  
Declare security in Tomcat. The security of WEB applications mainly lies in the corresponding Web. set in xml, Tomcat supports the basic http authentication mechanism and form-based authentication mechanism FROM (JSP website ).
  
Filter is a new function of Tomcat 4. It can be used to implement previously inconvenient or difficult to implement functions. These functions include:
  
Custom identity authentication for resource access (web pages, JSP pages, servlet;
Application-level resource access review and record;
Encrypted access to resources within the application scope, which is based on a customized encryption solution;
Timely conversion of accessed resources, including dynamic output from servlet and JSP.
  
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.