Using Apache to build a WEB server (1)

Source: Internet
Author: User
Tags http authentication perl script

Apache originated from the NCSAhttpd server and has been modified many times to become one of the most popular Web server software in the world. Apache is taken from the pronunciation of "a patchy server", which means a server full of patches, because it is a free software, so there are people who constantly develop new functions, new features, and modify the original defects for it. 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.
When a Web site is scaled up, servers are usually added or cluster nodes are expanded instead of processors. Apache is still the most popular Web server in the world so far, with a market share of about 60%. Many famous websites in the world, such as Amazon.com and Yahoo! , W3
Consortium and Financial Times are all products of Apache, its success 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.


The emergence of Apache is dramatic. After the ncsa www server project pause, those who use the ncsa www server began to exchange their patches for the server, and they soon realized that it was necessary to set up a forum to manage these patches. In this way, Apache was born.
Group. Later, this Group created Apache based on NCSA.

The main features of Apache are:

 

Can run on all computer platforms;

Supports the latest HTTP 1.1 protocol;

Simple and powerful file-based configuration;

Common Gateway Interface CGI is supported;

Supports virtual hosts;

Supports HTTP authentication;

Integrate the Perl script programming language;

Integrated proxy server;

Provides customizable server logs;

Support for server-side inclusion commands (SSI)

Support for Secure Socket Layer (SSL)

Tracking of user session processes;

Supports FastCGI;

Java Servlets is supported.

 


Install Apache

Next we will start a long journey to conquer Apache. Through step-by-step demand instances, we will learn how to use Apache step by step, from getting started to being proficient.


The system does not need too many computing resources to run Apache. It runs well on a Linux system with 6-10 MB hard disk space and 8 mb ram. However, running Apache alone may not be what you want to do. More likely, you want to run Apache to provide the WWW Service, start the CGI process, and make full use of all the amazing functions that WWW can provide. In this case, you need to provide additional disk space and memory space that reflect the load requirements. That is to say, if you only start the WWW Service, you do not need too many system resources, but you need more system resources to provide services to a large number of customers.


You can install the Apache server in the following three ways.

1. if Apache is installed in the Linux version, select the httpd service when selecting the server to be installed. The Linux installation program automatically installs Apache, make basic configurations.


2. Use the executable file package, which is suitable for beginners who are not familiar with compilation, because it is relatively simple.

Download the software package apache_1.3.29.tar.gz

Tar xvzf apache_1.3.29.tar.gz
This completes the installation, simple!

If you are using RedHat
For Linux, You can also download the apache_1.3.29.rpm software installation package, and then install it using the rpm-ivh apache_1.3.


3. If you want to make full use of the Apache server, you must compile Apache to customize its functions. Download the apache_xxx.tar.gz software package containing the apachesource code;
Then, run the tar command to unbind it; change the current directory to the src directory of the Apache source code release; copy the Configuration sample file (Configuration. tmpl) to the Configuration file;


Edit the Configuration options in the Configuration file:

 


Makefile configuration options: Some compilation options:

"CC =" A line specifies what compilation software is used for compiling, generally "CC = gcc ";

If you need to specify the additional flag (parameter) to the C compilation software, you can use:

EXTRA_CFLAGS =

EXTRA_LFLAGS =

If the system requires special libraries and include files, you can specify them here:

EXTRA_LIBS =

EXTRA_INCLUDES =

If you want to change the code optimization settings, you must remove the following comments. However

Then change it to the value you need:

# OPTIM =-O2

Rule Configuration option: used to determine what features are required. Generally, this option does not need to be changed.

Module configuration: the module is a component of Apache and adds new features to the Apache kernel. By using module configuration, you can customize the functions required on the Apache server, which is also a manifestation of Apache flexibility. The module configuration line is as follows:


AddModule modules/standard/mod_env.o

If you need the functions of the Apache server, add the module to the Configuration file Configuration using the AddModule statement.

The following table lists the functions of Apache modules:

Module name function default

Mod_access provides Host-Based Access Control Command y

Mod_actions can run the MIME-type CGI script or HTTP Request Method y

Mod_alias can execute URL redirection service y

Mod_asis enables documents to be sent to client y without an HTTP Header

Mod_auth supports user name and password stored in text files for authentication y

Mod_auth_dbm support using DBM file storage basic HTTP Authentication n

Mod_auth_mysql supports using MySQL database for basic HTTP Authentication n

Mod_auth_anon allows anonymous access to the region y to be authenticated

Mod_auth_external supports third-party authentication n

Mod_autoindex automatically generates a dynamic directory list y when the index file is missing.

Mod_cern_meta provides support for metadata n

Mod_cgi supports CGI y

Mod_dir can redirect any request to the command without the tail slash character y

Mod_env enables you to pass environment variables to CGI or SSI script n

Mod_expires lets you determine how Apache handles Expires y when the server responds to a request

Mod_headers can operate the HTTP Response Header labeled y

Mod_imap provides graph ing support n

Mod_include enables SSI n

Mod_info provides a comprehensive description of server configuration y

Mod_log_agent allows users to store proxy information in separate log files. n

Mod_log_config supports logging y

Mod_log_referer provides the function of writing the Referer header in the request to logs. n

Mod_mime is used to provide meta information about documents to the client. y

Mod_negotiation provides support for content negotiation y

Mod_setenvif enables you to create custom environment variable y

Mod_speling enables you to process URL requests containing spelling or case-insensitive characters n

Mod_status allows administrators to manage Apache y through the WEB

Mod_unique_id provides each request with a unique identifier n under special conditions.

Run "./configure" in the src directory ";

 

 

Compile Apache: Execute the command "make". Depending on the machine performance, it takes 5-30 minutes to compile Apache. Copy the compiled executable file httpd to the/etc/httpd/bin directory, and copy the configuration file: access. conf, httpd. conf, mime. types, srm. copy the conf file to the/etc/httpd/conf directory. So far, the installation is complete.


Notes

In Red Hat Linux, Apache stores all its configuration files and log files in the "/etc/httpd" directory, "/etc/httpd/conf" is the configuration file, and "/etc/httpd/log" is the log file.


At the same time, it will create a "/home/httpd" directory and create three subdirectories under it: "html/": store HTML (home page) files under this directory; "cgi-bin/": Some CGI programs can be stored in this directory; "icons/": some icons that come with the server are in this directory.


Configure Apache basics to run the WWW Server

The configuration files of Apache server software mainly include: "access. conf ": used to set the access mode and environment in the system;" httpd. conf ": used to set the basic environment for server startup;" srm. conf ": Mainly used for setting file resources;" mime. type: record the MIME format that the Apache server can recognize.


Before proceeding, I must tell you that Apache has adopted a series of default values during installation and has enabled the WWW server to run. You only need to connect the host installed with Linux + Apache to the Internet, and then store the home page under the "/home/httpd" directory.


The following describes the meanings of some of the most important configuration options, so that you can prepare the server with the minimum effort and minimum configuration.

Httpd. conftpd. conf is the main configuration file. It tells the server how to run it.


1. ServerType standalone | inetd

This configuration option specifies how to run the WEB server. Apache can run servers in two ways: standalone (independent) and inetd (run by inetd ). The standalone parameter indicates that a WEB service process listens for client requests in the background in a separate waiting process. If yes, a sub-process is generated to serve it. The inetd parameter indicates that the WEB service is not supported in the form of a separate waiting process. Instead, the super server Inetd waits for the process to do the work. When it receives a WEB service request from a client, it starts a WEB service process to serve it. From a functional perspective, the two methods are almost the same. But there is a big difference between them, the difference lies in the server performance. A server process running by inted exits immediately after it finishes requesting services. In standalone mode, the sub-WWW server processes need to be suspended for a period of time before exiting, which provides them with the opportunity to serve new requests again.


In standalone mode, there is no overhead for starting a new process for each request, so it is more efficient. inetd mode is considered to be more secure than standalone mode.


Standalone mode:

In this mode, the WWW server listens for connection requests from specific ports. When the client sends a connection request to a specific port address, the master server process starts the WWW Service process to serve the request. In addition, the master server must be notified of the specific end of the process listening.

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.