0163-0165.html
来自「linux-unix130.linux.and.unix.ebooks130 l」· HTML 代码 · 共 427 行
HTML
427 行
<HTML>
<HEAD>
<TITLE>Developer.com - Online Reference Library - 0672311739:RED HAT LINUX 2ND EDITION:Apache Server</TITLE>
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<SCRIPT>
<!--
function displayWindow(url, width, height) {
var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>
-->
<!-- ISBN=0672311739 //-->
<!-- TITLE=RED HAT LINUX 2ND EDITION //-->
<!-- AUTHOR=DAVID PITTS ET AL //-->
<!-- PUBLISHER=MACMILLAN //-->
<!-- IMPRINT=SAMS PUBLISHING //-->
<!-- PUBLICATION DATE=1998 //-->
<!-- CHAPTER=09 //-->
<!-- PAGES=0153-0174 //-->
<!-- UNASSIGNED1 //-->
<!-- UNASSIGNED2 //-->
<P><CENTER>
<a href="0160-0162.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0166-0169.html">Next</A>
</CENTER></P>
<A NAME="PAGENUM-163"><P>Page 163</P></A>
<!-- CODE SNIP //-->
<PRE>
</CENTER>
</FORM>
</BODY>
</HTML>
</PRE>
<!-- END CODE SNIP //-->
<P>Put this file in your htdocs directory. At this point, you are ready to test the
server.
</P>
<H4><A NAME="ch09_ 11">
Starting a Standalone Server
</A></H4>
<P>If you are running a standalone server, you need to start
httpd manually. You do so by entering the following line:
</P>
<!-- CODE SNIP //-->
<PRE>
# /sbin/httpd -f /etc/httpd/conf/httpd.conf
</PRE>
<!-- END CODE SNIP //-->
<P>Note that I started the standalone server from the root account, indicated by the pound
sign (#) at the beginning of the line. You need to start standalone servers by root so that two
important events occur:
</P>
<UL>
<LI> If your standalone server uses the default HTTP port (port 80), only the superuser
can bind to Internet ports that are lower than 1025.
<LI> Only processes owned by root can change their UID and GID as specified by the
User and Group directives. If you start the server under another UID, it will run with
the permissions of the user starting the process.
</UL>
<H4><A NAME="ch09_ 12">
Starting an inetd Server
</A></H4>
<P>As you probably guessed, you don't need to start an
inetd server. inetd starts httpd every time a request is received in the port assigned to the server.
inetd servers make good development platforms because configuration settings are reread every time you send a request.
</P>
<H3><A NAME="ch09_ 13">
Starting and Stopping the Server
</A></H3>
<P>The Apache server, httpd, has a few command-line options you can use to set some
defaults specifying where httpd will read its configuration directives. The Apache
httpd executable understands the following options:
</P>
<!-- CODE SNIP //-->
<PRE>
httpd [-d ServerRoot] [-f ConfigurationFile] [-x] [-v] [-?]
</PRE>
<!-- END CODE SNIP //-->
<P>The -d option overrides the location of the
ServerRoot directory. It sets the initial value of
the ServerRoot variable (the directory where the Apache server is installed) to whatever path
you specify. This default is usually read from the
ServerRoot directive in httpd.conf.
</P>
<P>The -f flag specifies the location of the main configuration file,
conf/httpd.conf. It reads and executes the configuration commands found on
ConfigurationFile on startup. If the
ConfigurationFile is not an absolute path (doesn't begin with a
/), its location is assumed to be relative to the path specified in the
ServerRoot directive in httpd.conf. By default, this
value is set to ServerRoot/conf/httpd.conf.
</P>
<A NAME="PAGENUM-164"><P>Page 164</P></A>
<P>The -x option is used by the developers of Apache as a debugging aid and should not be
used under normal server operation. It runs a single server process that does not create any children.
</P>
<P>The -v option prints the development version of the Apache server and terminates the process.
</P>
<P>The -? option prints the following usage information for the server:
</P>
<!-- CODE SNIP //-->
<PRE>
Usage: httpd [-d directory] [-f file] [-v]
-d directory : specify an alternate initial ServerRoot
-f file : specify an alternate ServerConfigFile
</PRE>
<!-- END CODE SNIP //-->
<H4><A NAME="ch09_ 14">
The start Script
</A></H4>
<P>I have developed a small start script that launches the server with all the command-line
settings I use. This script saves me a little typing when I'm trying tasks that require me to
start and stop the server. Here's the listing for the
start script:
</P>
<!-- CODE SNIP //-->
<PRE>#!/bin/sh
/sbin/httpd -f /etc/httpd/conf/httpd.conf
</PRE>
<!-- END CODE SNIP //-->
<P>You can create such a script by just typing it into a file (one per script). After you finish
entering it, to turn it into executable, type
</P>
<!-- CODE SNIP //-->
<PRE>
cd WhereEverYouEnterThem
chmod 755 start stop restart
</PRE>
<!-- END CODE SNIP //-->
<P>You might want to store the script in a place where it is convenient, such as
/usr/local/bin.
</P>
<P>The Apache RPM installs a script in /etc/rc3.d named
S85httpd that will start the server with the default
configuration file.
</P>
<H4><A NAME="ch09_ 15">
The stop Script
</A></H4>
<P>The server is designed to stop gracefully when it is sent a
TERM (terminate) signal. When the server starts, it spawns several children processes; it therefore becomes more difficult to
terminate. Apache automatically kills any children processes when the main process is killed.
Luckily, the developers of Apache put the process ID of the main process in a file where you
can easily obtain the ID. My stop script makes use of the
PidFile (/usr/local/etc/httpd/logs/PidFile) file.
</P>
<P>The following is the listing for the stop script:
</P>
<!-- CODE SNIP //-->
<PRE>
#!/bin/sh
#Stop Apache Script
kill `cat /var/log/httpd/httpd.pid'
</PRE>
<!-- END CODE SNIP //-->
<P>The Apache RPM installs a script named K25httpd in
/etc/rc0.d/ that will stop the server.
</P>
<H4><A NAME="ch09_ 16">
The restart Script
</A></H4>
<P>The server is designed to restart if it receives a
-HUP (hang-up) signal. On receiving this type of signal, the server stops and immediately restarts, rereading its configuration files.
</P>
<A NAME="PAGENUM-165"><P>Page 165</P></A>
<P>Here's the listing for the restart script:
</P>
<!-- CODE SNIP //-->
<PRE>
#!/bin/sh
#Restart Apache Script
kill -HUP `cat /var/log/httpd/logs/httpd.pid'
</PRE>
<!-- END CODE SNIP //-->
<P>This convenient script automates the process. Any time you modify any of the
configuration files, you need to restart the server to enable the changes. Using
htrestart makes performing this process easy.
</P>
<H3><A NAME="ch09_ 17">
Configuration File Listings
</A></H3>
<P>For your convenience, I have provided listings of the various configuration files I talked
about in this chapter. You might notice some differences between the files listed here and
configuration files of source you download from the Internet. These differences are normal because
newer versions of the server might have been released since this printing.
</P>
<P>Listing 9.1 shows the server configuration file.
</P>
<P>Listing 9.1. conf/httpd.conf.
</P>
<!-- CODE //-->
<PRE>
# This is the main server configuration file. See URL http://www.apache.org/
# for instructions.
# Do NOT simply read the instructions in here without understanding
# what they do, if you are unsure consult the online docs. You have been
# warned.
# Originally by Rob McCool
# ServerType is either inetd, or standalone.
ServerType standalone
# If you are running from inetd, go to "ServerAdmin".
# Port: The port the standalone listens to. For ports < 1023, you will
# need httpd to be run as root initially.
Port 80
# HostnameLookups: Log the names of clients or just their IP numbers
# e.g. www.apache.org (on) or 204.62.129.132 (off)
HostnameLookups on
# If you wish httpd to run as a different user or group, you must run
# httpd as root initially and it will switch.
# User/Group: The name (or #number) of the user/group to run httpd as.
# On SCO (ODT 3) use User nouser and Group nogroup
User nobody
Group #-1
</PRE>
<!-- END CODE //-->
<PRE>
continues
</PRE>
<!-- END CODE SNIP //-->
<P><CENTER>
<a href="0160-0162.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0166-0169.html">Next</A>
</CENTER></P>
</td>
</tr>
</table>
<!-- begin footer information -->
</body></html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?