0160-0162.html
来自「linux-unix130.linux.and.unix.ebooks130 l」· HTML 代码 · 共 335 行
HTML
335 行
<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="0157-0159.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0163-0165.html">Next</A>
</CENTER></P>
<A NAME="PAGENUM-160"><P>Page 160</P></A>
<P>The Port directive has no effect on an inetd server. A standalone server uses this
configuration information to learn which port it should be listening to. Because
inetd does the binding between the port and the software, this setting has no effect on an
inetd configuration.
</P>
<H4><A NAME="ch09_ 9">
Configuring inetd
</A></H4>
<P>inetd is the "Internet superserver." It gets started when the machine boots by
/etc/rc. After it is launched, inetd listens for connections on Internet socket ports. When it finds a
connection, it starts the program responsible for managing that port. When the request is served and
the program exits, inetd continues to listen for additional requests on that port.
</P>
<P>To make Apache work from inetd, you need to edit
/etc/inetd.conf and /etc/services. Configuring an
inetd server requires a bit more system configuration than a standalone server.
</P>
<P>First, you need to edit your /etc/services file. The
/etc/services database contains information about all known services available on the Internet. Each service is represented by a
single line listing the following information:
</P>
<BLOCKQUOTE>
Official service name<BR>
Port number<BR>
Protocol name<BR>
Aliases by which the service is known
</BLOCKQUOTE>
<P>Each entry is separated by a tab or spaces. An entry describing
httpd looks like this:
</P>
<!-- CODE SNIP //-->
<PRE>
http portnumber/tcp httpd httpd
</PRE>
<!-- END CODE SNIP //-->
<TABLE BGCOLOR=#FFFF99><TR><TD><B>TCP/IP RESERVED PORTS</B>
</TD></TR><TR><TD><BLOCKQUOTE>
TCP/IP ports range from 0 to 65,535; however, the first 1,024 ports are reserved.
A reserved port is controlled and assigned by the IANA and, on most systems, can be
used only by system (or root) processes or by programs executed by privileged users.
(The IANA is the Internet Assigned Numbers
Authority. More details about the IANA and reserved ports are available at
<a href="http://www.sockets.com/services.htm#wellknownports.)">http://www.sockets.com/services.htm#WellKnownPorts.)</A>
If you want to run the server at port 80 (the default for
httpd), the superuser must start httpd.
</BLOCKQUOTE>
</TD></TR></TABLE>
<P>Set portnumber to the port number on which you want to run the server. Typically, this
port will be port 80 for a standalone server.
inetd servers run better at port 8080, so your entry
will look like this:
</P>
<!-- CODE SNIP //-->
<PRE>
http 8080/tcp httpd httpd
</PRE>
<!-- END CODE SNIP //-->
<A NAME="PAGENUM-161"><P>Page 161</P></A>
<P>If you are running NetInfo, you can type this line into a temporary file, such as
/tmp/services, and then run
</P>
<!-- CODE SNIP //-->
<PRE>
niload services . < /tmp/services
</PRE>
<!-- END CODE SNIP //-->
<P>Next, you need to edit /etc/inetd.conf to configure
inetd to listen for httpd requests. Each line in
inetd.conf contains the following information:
</P>
<BLOCKQUOTE>
Service name<BR>
Socket type<BR>
Protocol<BR>
Wait/no wait<BR>
User the server program will run as<BR>
Server program<BR>
Server program arguments
</BLOCKQUOTE>
<P>My completed entry looks like this:
</P>
<!-- END CODE SNIP //--><PRE>
httpd stream tcp nowait nobody /sbin/httpd httpd -f /etc/httpd/conf/httpd.conf
<!-- END CODE SNIP //--></PRE>
<CENTER>
<TABLE BGCOLOR="#FFFF99">
<TR><TD><B>
WARNING
</B></TD></TR>
<TR><TD>
<BLOCKQUOTE>
The preceding example starts the server as
nobody. Typically, you will want a standalone server to be started by the root user so that the server can bind to port 80, the
standard HTTP port, and be able to change the UID and GID of its children processes. When
the standalone server starts, it forks children processes. These children processes run with a
UID of nobody and a GID of nogroup, unless you specified a different setting with the
User and Group directives. The children processes handle the HTTP requests. The main
process, owned by root, has as its duty the creation and destruction of its children processes.
This makes the standard, standalone server secure.<BR>
<BR>
If you specify the root UID in this example with the intention of running the
inetd server on port 80, the process handling the request is owned by root. This setup can create
security problems; unlike a standalone server, the
inetd server doesn't fork any children processes, so it handles requests with the UID and GID of the process owner.
</BLOCKQUOTE></TD></TR>
</TABLE></CENTER>
<P>After adding the httpd entry to /etc/inetd.conf, you need to restart
inetd. You can easily do so by finding out the
inetd process number by using ps and sending it a
HANGUP signal:
</P>
<!-- CODE SNIP //-->
<PRE>
# kill -HUP InetdProcessID
</PRE>
<!-- END CODE SNIP //-->
<P>Replace the InetdProcessID with the process number listed by the
ps command. If the PID listed is 86, you would type
kill -HUP 86.
</P>
<P>inetd then restarts, rereading the configuration file that instructs it to listen for a request
for port 8080.
</P>
<A NAME="PAGENUM-162"><P>Page 162</P></A>
<H3><A NAME="ch09_ 10">
Running the Web Server for the First Time
</A></H3>
<P>Before you can run the server for the first time, you need to create an HTML document.
The standard Apache distribution includes such a file, but I have created another file that is
more useful, and I am sure that you'll use it time and time again. Using your favorite text
editor, create a file called index.html inside the
htdocs directory with this content:
</P>
<!-- CODE //-->
<PRE>
<HTML>
<HEAD>
<TITLE>Red Hat Linux Unleashed</TITLE>
</HEAD>
<BODY BGCOLOR="#ffffff" LINK="#000080" VLINK="#000080">
<H1><CENTER>Red Hat Linux Unleashed </CENTER></H1>
<H2><CENTER>Congratulations! Your Apache server was successfully
installed.</CENTER></H2>
<H3>Here are some interesting sites that host information about
the Apache server: </H3>
<UL>
<LI>The official homepage for the
<A HREF="http://www.apache.org">Apache Group</A>
<LI>The official homepage for
<A HREF="http://www.us.apache-ssl.com">Community Connexion</A>
developers of Stronghold: Apache-SSL-US (A Netscape compatible
SSL server based on Apache)
<LI>The official homepage for
<A HREF="http://www.algroup.co.uk/Apache-SSL">Apache-SSL</A>
(A Netscape compatible SSL server based on Apache - only available
to users outside of the United States).
<LI><A HREF="http://www.zyzzyva.com/server/module_registry/">
Apache Module Registry</A>, the place where you can find information
about 3<SUP>rd</SUP> party Apache modules and other development stuff.
<LI><A HREF="http://www.apacheweek.com">The Apache Week Home</A>,
here you will find an essential weekly guide dedicated to Apache server
Âinformation.
<LI><A HREF="http://www.ukweb.com">UK Web's Apache Support Center</A>
<LI><A HREF="http://www.fastcgi.com">The FastCGI Website</A>
</UL>
<P>
<STRONG>Deja News a very handy USENET news search engine:</STRONG>
<FORM ACTION="http://search.dejanews.com/dnquery.xp" METHOD=POST>
<P>
<CENTER>
<STRONG>Quick Search For:</STRONG> <INPUT NAME="query" VALUE="Apache" SIZE="37">
<INPUT TYPE="submit" VALUE="Search!"><INPUT NAME="defaultOp" VALUE="AND"
ÂTYPE="hidden">
<INPUT NAME="svcclass" VALUE="dncurrent" TYPE="hidden">
<INPUT NAME="maxhits" VALUE="20" TYPE="hidden">
</PRE>
<!-- END CODE //-->
<P><CENTER>
<a href="0157-0159.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0163-0165.html">Next</A>
</CENTER></P>
</td>
</tr>
</table>
<!-- begin footer information -->
</body></html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?