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 &quot;Internet superserver.&quot; 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 . &lt; /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>

&lt;HTML&gt;

&lt;HEAD&gt;

&lt;TITLE&gt;Red Hat Linux Unleashed&lt;/TITLE&gt;

&lt;/HEAD&gt;

&lt;BODY BGCOLOR=&quot;#ffffff&quot; LINK=&quot;#000080&quot; VLINK=&quot;#000080&quot;&gt;

&lt;H1&gt;&lt;CENTER&gt;Red Hat Linux Unleashed &lt;/CENTER&gt;&lt;/H1&gt;

&lt;H2&gt;&lt;CENTER&gt;Congratulations! Your Apache server was successfully

installed.&lt;/CENTER&gt;&lt;/H2&gt;



&lt;H3&gt;Here are some interesting sites that host information about

the Apache server: &lt;/H3&gt;



&lt;UL&gt;

&lt;LI&gt;The official homepage for the

&lt;A HREF=&quot;http://www.apache.org&quot;&gt;Apache Group&lt;/A&gt;



&lt;LI&gt;The official homepage for

&lt;A HREF=&quot;http://www.us.apache-ssl.com&quot;&gt;Community Connexion&lt;/A&gt;

developers of Stronghold: Apache-SSL-US (A Netscape compatible

SSL server based on Apache)



&lt;LI&gt;The official homepage for

&lt;A HREF=&quot;http://www.algroup.co.uk/Apache-SSL&quot;&gt;Apache-SSL&lt;/A&gt;

(A Netscape compatible SSL server based on Apache - only available

to users outside of the United States).



&lt;LI&gt;&lt;A HREF=&quot;http://www.zyzzyva.com/server/module_registry/&quot;&gt;

Apache Module Registry&lt;/A&gt;, the place where you can find information

about 3&lt;SUP&gt;rd&lt;/SUP&gt; party Apache modules and other development stuff.



&lt;LI&gt;&lt;A HREF=&quot;http://www.apacheweek.com&quot;&gt;The Apache Week Home&lt;/A&gt;,

here you will find an essential weekly guide dedicated to Apache server

&Acirc;information.



&lt;LI&gt;&lt;A HREF=&quot;http://www.ukweb.com&quot;&gt;UK Web's Apache Support Center&lt;/A&gt;



&lt;LI&gt;&lt;A HREF=&quot;http://www.fastcgi.com&quot;&gt;The FastCGI Website&lt;/A&gt;

&lt;/UL&gt;



&lt;P&gt;

&lt;STRONG&gt;Deja News a very handy USENET news search engine:&lt;/STRONG&gt;

&lt;FORM ACTION=&quot;http://search.dejanews.com/dnquery.xp&quot; METHOD=POST&gt;



&lt;P&gt;

&lt;CENTER&gt;

&lt;STRONG&gt;Quick Search For:&lt;/STRONG&gt; &lt;INPUT NAME=&quot;query&quot; VALUE=&quot;Apache&quot; SIZE=&quot;37&quot;&gt;

&lt;INPUT TYPE=&quot;submit&quot; VALUE=&quot;Search!&quot;&gt;&lt;INPUT NAME=&quot;defaultOp&quot; VALUE=&quot;AND&quot;

&Acirc;TYPE=&quot;hidden&quot;&gt;

&lt;INPUT NAME=&quot;svcclass&quot; VALUE=&quot;dncurrent&quot; TYPE=&quot;hidden&quot;&gt;

&lt;INPUT NAME=&quot;maxhits&quot; VALUE=&quot;20&quot; TYPE=&quot;hidden&quot;&gt;

</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 + -
显示快捷键?