📄 asg02.htm
字号:
<HTML>
<HEAD>
<TITLE>Apache Server Survival Guide asg02.htm </TITLE>
<LINK REL="ToC" HREF="index.htm" tppabs="http://docs.rinet.ru:8080/Apachu/index.htm">
<LINK REL="Index" HREF="htindex.htm" tppabs="http://docs.rinet.ru:8080/Apachu/htindex.htm">
<LINK REL="Next" HREF="asg03.htm" tppabs="http://docs.rinet.ru:8080/Apachu/asg03.htm">
<LINK REL="Previous" HREF="asg01.htm" tppabs="http://docs.rinet.ru:8080/Apachu/asg01.htm"></HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080">
<!--#exec cmd="/www/docs/ssi-bin/restricted_search.ssi"-->
<!--#exec cmd="/www/docs/ssi-bin/inc.ssi"-->
<A NAME="I0"></A>
<H2>Apache Server Survival Guide asg02.htm</H2>
<P ALIGN=center>
<A HREF="asg01.htm" tppabs="http://docs.rinet.ru:8080/Apachu/asg01.htm" TARGET="_self"><IMG SRC="purprev.gif" tppabs="http://docs.rinet.ru:8080/Apachu/purprev.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Previous Page"></A>
<A HREF="index.htm" tppabs="http://docs.rinet.ru:8080/Apachu/index.htm" TARGET="_self"><IMG SRC="purtoc.gif" tppabs="http://docs.rinet.ru:8080/Apachu/purtoc.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="TOC"></A>
<A HREF="asg03.htm" tppabs="http://docs.rinet.ru:8080/Apachu/asg03.htm" TARGET="_self"><IMG SRC="purnext.gif" tppabs="http://docs.rinet.ru:8080/Apachu/purnext.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Next Page"></A>
<HR ALIGN=CENTER>
<P>
<UL>
<UL>
<UL>
<LI>
<A HREF="#E68E15" >Installing a Precompiled Server</A>
<LI>
<A HREF="#E68E16" >Installing from the Source</A>
<UL>
<LI>
<A HREF="#E69E1" >Editing the Configuration File</A>
<LI>
<A HREF="#E69E2" >Running the Configure Script</A>
<LI>
<A HREF="#E69E3" >Running make</A></UL>
<LI>
<A HREF="#E68E17" >Runtime Server Configuration Settings</A>
<UL>
<LI>
<A HREF="#E69E4" >Editing httpd.conf</A>
<LI>
<A HREF="#E69E5" >Editing srm.conf</A>
<LI>
<A HREF="#E69E6" >Editing access.conf</A></UL>
<LI>
<A HREF="#E68E18" >Configuring an inetd Server</A>
<UL>
<LI>
<A HREF="#E69E7" >Configuring inetd</A></UL>
<LI>
<A HREF="#E68E19" >Running the Web Server for the First Time</A>
<UL>
<LI>
<A HREF="#E69E8" >Starting Up a Standalone Server</A>
<LI>
<A HREF="#E69E9" >Starting Up an inetd Server</A></UL>
<LI>
<A HREF="#E68E20" >Starting and Stopping the Server</A>
<UL>
<LI>
<A HREF="#E69E10" >The start Script</A>
<LI>
<A HREF="#E69E11" >The stop Script</A>
<LI>
<A HREF="#E69E12" >The restart Script</A>
<LI>
<A HREF="#E69E13" >Auto-Starting the Web Server at Boot Time</A></UL>
<LI>
<A HREF="#E68E21" >Testing the Newly Installed Server</A>
<LI>
<A HREF="#E68E22" >Configuration File Listings</A>
<UL>
<LI>
<A HREF="#E69E14" >src/Configuration File</A>
<LI>
<A HREF="#E69E15" >The Server Configuration File: conf/httpd.conf</A>
<LI>
<A HREF="#E69E16" >The Resource Configuration File: conf/srm.conf</A>
<LI>
<A HREF="#E69E17" >The Global Access Configuration File: conf/access.conf</A></UL>
<LI>
<A HREF="#E68E23" >Summary</A></UL></UL></UL>
<HR ALIGN=CENTER>
<A NAME="E66E2"></A>
<H1 ALIGN=CENTER>
<CENTER>
<FONT SIZE=6 COLOR="#FF0000"><B>2</B></FONT></CENTER></H1>
<BR>
<A NAME="E67E4"></A>
<H2 ALIGN=CENTER>
<CENTER>
<FONT SIZE=6 COLOR="#FF0000"><B>Installing and Configuring the Apache Server</B></FONT></CENTER></H2>
<BR>
<P>This chapter guides you through the installation and configuration of Apache using a basic setup. You will find the latest stable server software, as well as the latest beta releases of the Apache source distribution, on the Apache group's Web server (<A HREF="javascript:if(confirm('http://www.apache.org/ \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address. \n\nDo you want to open it from the server?'))window.location='http://www.apache.org/'" tppabs="http://www.apache.org/"> http://www.apache.org</A>). A copy of the latest release available at the time this book was written (Apache 1.1.1) is included on the CD-ROM that accompanies this book.
<BR>
<P>If you don't have access to a compiler, you can still install Apache provided that you can find a precompiled version of the server that works with your hardware and operating system. I have included the precompiled servers I found at the Apache group's Web server, including AUX 3.1, BSDI 1.1 and 2.0, FREEBSD 2.1, HPUX 9.07, IRIX 5.3, Linux, NETBSD 1.1, SOLARIS 2.4, SunOS 4.1.3, and UNIXWARE 1.1.2., and others.
<P>
<a href="javascript:if(confirm('http://docs.rinet.ru:8080/Apachu/02fig00.gif \n\nThis file was not retrieved by Teleport Pro, because it was redirected to an invalid location. You should report this problem to the site\'s webmaster. \n\nDo you want to open it from the server?'))window.location='http://docs.rinet.ru:8080/Apachu/02fig00.gif'" tppabs="http://docs.rinet.ru:8080/Apachu/02fig00.gif"><B>Fig. 2.1</B></A><I> The Apache home page. Notice this site is mirrored around the world.</I>
<P>
<BR>
<P>The Apache site provides links to various mirror sites from which you can download the software. Choose the one that is geographically closest to you from the various sites listed on the Apache home page.
<BR>
<P>To install Apache in its default location at /usr/local/etc/httpd, you may need to be the superuser. You'll need to know the root password of the machine in which you are installing Apache. If you don't know how to become root, please contact your local system administrator. Put the distribution archive in the /tmp directory. A sequence of commands to do the installation from /tmp might look like this:
<BR>
<PRE>
<FONT COLOR="#000080">mkdirs /usr/local/etc (your system may use 'mkdir -p /usr/local/etc' instead)
cd /usr/local/etc
mv /tmp/apache_1.1.1.tar.gz /usr/local/etc
gzcat apache_1.1.1.tar.gz | tar -xf -
mv apache_1.1.1 httpd</FONT></PRE>
<P>If your system does not support gzcat, you may need to do a gunzip -c instead.
<BR>
<P>Note that depending on the version you are installing, you will be left with a directory called apache_x.x.x. Now you should have a tree under httpd that contains the complete distribution of Apache. This directory tree contains configuration templates and other resources that the server needs for its operation. Be sure not to move or rename any of the files and directories, unless you know what you are doing.
<BR>
<BR>
<A NAME="E68E15"></A>
<H3 ALIGN=CENTER>
<CENTER>
<FONT SIZE=5 COLOR="#FF0000"><B>Installing a Precompiled Server</B></FONT></CENTER></H3>
<BR>
<P>Apache has been compiled for many platforms, and chances are that a prebuilt copy of the server exists for your setup. If you are interested in compiling the source, you might want to skip to the section in this chapter titled, "Installing from the Source" because it offers information on how to build the Apache HTTP server.
<BR>
<P>Installing a precompiled server is very similar to installing a source-only distribution. The only difference is that a compiled httpd binary already exists in the server's src directory. The compiled binary of the Apache server is called httpd. On binary distributions, the binary is usually labeled httpd-<I>architecture</I><I>,</I> where <I>architecture</I> is the name of the OS you are installing. For Linux, the httpd binary is called httpd-linux.
<BR>
<P>Although it is perfectly fine to keep the binary in the src directory, I like to install the binary at the top of the distribution tree. In this example, that is /usr/local/etc/httpd/httpd. Sometimes, the binary distribution has not been stripped. Stripping removes extra symbol information that the linker left from the compilation linking process. Removing this extra information using strip usually makes the binary about 30 to 40 percent smaller. I also like to protect the executable from any user trying to alter it. An easy way to do this is by changing the owner and group of the executable to root and the group to wheel. Then remove all write privileges to the binary from everyone but the owner. To chown and chmod a file (<I>ch</I>ange <I>own</I>er and <I>ch</I>ange <I>mod</I>e) to root, you need to do this as the superuser. The following installation steps might look something like this:
<BR>
<OL>
<LI> 1. cd /usr/local/etc/httpd
<BR>
<BR>
<LI> 2. cp src/httpd-linux httpd
<BR>
<BR>
<LI> 3. strip httpd
<BR>
<BR>
<LI> 4. chown root.wheel httpd
<BR>
<BR>
<LI> 5. chmod 755 httpd
<BR>
<BR>
</OL>
<P>If you are installing a precompiled server, you can skip to the section titled, "Runtime Server Configuration Settings."
<BR>
<BR>
<A NAME="E68E16"></A>
<H3 ALIGN=CENTER>
<CENTER>
<FONT SIZE=5 COLOR="#FF0000"><B>Installing from the Source</B></FONT></CENTER></H3>
<BR>
<P>Installing from the source is a little more time-consuming, but it will force you to get familiar with the source distribution of the Apache server. It will also give you the opportunity to customize the modules that are built into Apache. Many of these modules provide functionality that will make your server more powerful. All the files you will need to edit to build the binary are in the src directory. Building from the source is a three-step process:
<BR>
<OL>
<LI> 1. Edit the one-time configuration file, src/Configuration.
<BR>
<BR>
<LI> 2. Run the Configure script.
<BR>
<BR>
<LI> 3. Run make.
<BR>
<BR>
</OL>
<BR>
<A NAME="E69E1"></A>
<H4 ALIGN=CENTER>
<CENTER>
<FONT SIZE=4 COLOR="#FF0000"><B>Editing the </B><B>Configuration</B><B> File</B></FONT></CENTER></H4>
<BR>
<P>Before you can compile the software, you need to edit the configuration file and set some compile-time options that address the peculiarities of your operating system (and, in some cases, the hardware on which you are going to be running the server). Apache supports the concept of modules that extend and enhance the functionality of the server. However, in order for some of these modules to work, they have to be enabled in the configuration file. The configuration file can be found in /usr/local/etc/httpd/src. To make a copy of the configuration file, type in the following:
<BR>
<PRE>
<FONT COLOR="#000080">cd /usr/local/etc/httpd/src
cp Configuration.tmpl Configuration</FONT></PRE>
<P>Using your favorite editor, read and edit the configuration file you just created. A listing of the default configuration files is included at the end of this chapter for your reading enjoyment.
<BR>
<P>I kept all the default settings with the exception of changing the compiler and compilation options to match my hardware and operating system. This is executed by removing the comments (the # signs) from the AUX_CFLAGS and AUX_LIBS defines found on the configuration file. Remember to comment out (put in a #) in front of other settings that may not apply to your system configuration.
<BR>
<BR>
<A NAME="E69E2"></A>
<H4 ALIGN=CENTER>
<CENTER>
<FONT SIZE=4 COLOR="#FF0000"><B>Running the </B><B>Configure</B><B> Script</B></FONT></CENTER></H4>
<BR>
<P>After you edit the configuration file, you need to run the Configure script. The Configure script is a Bourne shell script that uses the configuration file you edited (src/Configuration) to generate a new Makefile and modules.c to match the options you set in the compilation configuration file. To do this, type the following into your terminal program:
<BR>
<PRE>
<FONT COLOR="#000080">cd /usr/local/etc/httpd/src
./Configure</FONT></PRE>
<BLOCKQUOTE>
<BLOCKQUOTE>
<HR ALIGN=CENTER>
<BR>
<NOTE>Configure allows you to specify a configuration file on the command line by using the -file flag:
<BR>Configure -file NEXTSTEP.configuration
<BR> Using alternate config file NEXTSTEP.configuration
<BR>This feature is useful if you need to maintain various different configurations for several different machines.</NOTE>
<BR>
<HR ALIGN=CENTER>
</BLOCKQUOTE></BLOCKQUOTE>
<BR>
<A NAME="E69E3"></A>
<H4 ALIGN=CENTER>
<CENTER>
<FONT SIZE=4 COLOR="#FF0000"><B>Running </B><B>make</B></FONT></CENTER></H4>
<BR>
<P>If Configure proceeded normally, you should be able to build the server binary at this point. To build the binary, type this on your terminal:
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">make</FONT></PRE>
<P>After a few minutes, depending on the speed of your hardware, you will have a compiled version of the Web server. It is called httpd and is on the /usr/local/etc/apache/src directory. The current version of the Apache source code does not have an install target for make, so you'll have to copy and strip the executable by hand:
<BR>
<PRE>
<FONT COLOR="#000080">cp httpd ../httpd
cd ..
strip httpd
chown root.wheel httpd
chmod 755 httpd</FONT></PRE>
<BR>
<A NAME="E68E17"></A>
<H3 ALIGN=CENTER>
<CENTER>
<FONT SIZE=5 COLOR="#FF0000"><B>Runtime Server Configuration Settings</B></FONT></CENTER></H3>
<BR>
<P>Apache reads its configuration settings from three files: access.conf, httpd.conf, and srm.conf. Primarily, this has been done to maintain backward compatibility with the NCSA server, but the reasoning behind this organization makes good sense. The configuration files reside in the conf subdirectory of the server distribution. Sample configuration files are included in the software distribution; they are named access.conf-dist, httpd.conf-dist, and srm.conf-dist, respectively. You will need to create copies of these files without the -dist portion:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -