⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 asg02.htm

📁 apache技术手册
💻 HTM
📖 第 1 页 / 共 5 页
字号:

<UL>

<UL>

<P>User the server program will run as

</UL></UL>

<UL>

<UL>

<P>Server program

</UL></UL>

<UL>

<UL>

<P>Server program arguments

<BR>

</UL></UL>

<P>My completed entry looks like this:

<BR>

<PRE>

<FONT COLOR="#000080">httpd stream tcp nowait nobody /usr/local/etc/httpd/httpd httpd -f /usr/ local/etc/httpd/conf/httpd.conf</FONT></PRE>

<BLOCKQUOTE>

<BLOCKQUOTE>

<HR ALIGN=CENTER>

<BR>

<NOTE>The previous example will start the server as nobody. Typically, you will want a standalone server to be started by the root user so that the server is able to 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 up, 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 are the ones that handle 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>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 may 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.</NOTE>

<BR>

<HR ALIGN=CENTER>

</BLOCKQUOTE></BLOCKQUOTE>

<P>After adding the httpd entry to /etc/inetd.conf, you'll need to restart inetd. You can easily do this by finding out the inetd process number with ps and sending it a HANGUP signal:

<BR>

<BR>

<PRE>

<FONT COLOR="#000080"># kill -HUP <I>InetdProcessID</I></FONT></PRE>

<P>Replace the <I>InetdProcessID</I><I> </I>with<I> </I>the process number listed by the ps command. If the PID listed was 86, you would type kill -HUP 86.

<BR>

<P>inetd will restart, rereading its configuration file that will instruct it to listen for request for port 8080.

<BR>

<BR>

<A NAME="E68E19"></A>

<H3 ALIGN=CENTER>

<CENTER>

<FONT SIZE=5 COLOR="#FF0000"><B>Running the Web Server for the First Time</B></FONT></CENTER></H3>

<BR>

<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 which is more useful and I am sure that you'll use time and again. Using your favorite text editor, create a file called index.html inside the htdocs directory with this content:

<BR>

<PRE>

<FONT COLOR="#000080">&lt;HTML&gt;

&lt;HEAD&gt;

&lt;TITLE&gt;Apache Server Survival Guide&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;Apache Server Survival Guide &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 nformation.

&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; 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;

&lt;/CENTER&gt;

&lt;/FORM&gt;

&lt;/BODY&gt;

&lt;/HTML&gt;</FONT></PRE>

<P>Put this file in your htdocs directory. At this point you are ready to test the server.

<BR>

<P><A NAME="I9"></A><A NAME="I10"></A><A NAME="I11"></A><A NAME="I12"></A><A NAME="I13"></A><A NAME="I14"></A><A NAME="I15"></A><B>[ic:CD-ROM]</B>The machine-readable text for the file you just created is included in server/setup/index.html, and it should be placed in <I>DocumentRoot</I>/index.html.

<BR>

<BR>

<A NAME="E69E8"></A>

<H4 ALIGN=CENTER>

<CENTER>

<FONT SIZE=4 COLOR="#FF0000"><B>Starting Up a Standalone Server</B></FONT></CENTER></H4>

<BR>

<P>If you are running a standalone server, you'll need to start httpd manually. This is how you do it:

<BR>

<BR>

<PRE>

<FONT COLOR="#000080"># /usr/local/etc/httpd/httpd -f /usr/local/etc/httpd/conf/httpd.conf</FONT></PRE>

<P>Please note that I started the standalone server from the root account, indicated by the pound sign (#) at the beginning of the line. Standalone servers need to be started by root so two important things happen:

<BR>

<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.

<BR>

<BR>

<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.

<BR>

<BR>

</UL>

<BR>

<A NAME="E69E9"></A>

<H4 ALIGN=CENTER>

<CENTER>

<FONT SIZE=4 COLOR="#FF0000"><B>Starting Up an </B><B>inetd</B><B> Server</B></FONT></CENTER></H4>

<BR>

<P>As you probably guessed, you don't need to start an inetd server. inetd will start httpd every time a request is received in the port assigned to the server. inetd servers make good development platform because configuration settings are reread every time you send a request.

<BR>

<BR>

<A NAME="E68E20"></A>

<H3 ALIGN=CENTER>

<CENTER>

<FONT SIZE=5 COLOR="#FF0000"><B>Starting and Stopping the Server</B></FONT></CENTER></H3>

<BR>

<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:

<BR>

<BR>

<PRE>

<FONT COLOR="#000080">httpd [-d <I>ServerRoot</I>] [-f <I>ConfigurationFile</I>] [-x] [-v] [-?]</FONT></PRE>

<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:

<BR>

<P>The -f flag specifies the location of the main configuration file, conf/httpd.conf. Reads and executes the configuration commands found on <I>ConfigurationFile</I> on startup. If the <I>ConfigurationFile</I> is not an absolute path (doesn't begin with a /), its location is assumed to be relative of the path specified in the ServerRoot directive in httpd.conf. By default, this value is set to <I>ServerRoot</I>/conf/httpd.conf.

<BR>

<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.

<BR>

<P>The -v option prints the development version of the Apache server and terminates the process.

<BR>

<P>The -? option prints the following usage information for the server:

<BR>

<PRE>

<FONT COLOR="#000080">Usage: httpd [-d directory] [-f file] [-v]

-d directory : specify an alternate initial ServerRoot

-f file : specify an alternate ServerConfigFile</FONT></PRE>

<BR>

<A NAME="E69E10"></A>

<H4 ALIGN=CENTER>

<CENTER>

<FONT SIZE=4 COLOR="#FF0000"><B>The </B><B>start</B><B> Script</B></FONT></CENTER></H4>

<BR>

<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 things that require me to start and stop the server.

<BR>

<P>You can create this script by just typing it into a file (one per script). When you are done entering it, to turn it into executable, type:

<BR>

<PRE>

<FONT COLOR="#000080">cd WhereEverYouEnterThem

chmod 755 start stop restart</FONT></PRE>

<P>You may want to store the script in a place where it is convenient, such as /usr/local/bin. Here's the listing for the start script:

<BR>

<PRE>

<FONT COLOR="#000080">#!/bin/sh

/usr/local/etc/httpd/httpd -f /usr/local/etc/httpd/conf/httpd.conf</FONT></PRE>

<BR>

<A NAME="E69E11"></A>

<H4 ALIGN=CENTER>

<CENTER>

<FONT SIZE=4 COLOR="#FF0000"><B>The </B><B>stop</B><B> Script</B></FONT></CENTER></H4>

<BR>

<P>The server is designed to stop gracefully when its sent a TERM (terminate) signal. Because when the server starts it spawns several children processes, it becomes a little 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 of the process. My stop script makes use of the <I>PidFile</I> (/usr/local/etc/httpd/logs/PidFile) file.

<BR>

<P>This is the listing to the stop script:

<BR>

<PRE>

<FONT COLOR="#000080">#!/bin/sh

#Stop Apache Script

kill 'cat /usr/local/etc/httpd/logs/httpd..pid'</FONT></PRE>

<BR>

<A NAME="E69E12"></A>

<H4 ALIGN=CENTER>

<CENTER>

<FONT SIZE=4 COLOR="#FF0000"><B>The </B><B>restart</B><B> Script</B></FONT></CENTER></H4>

<BR>

<P>The server is designed to restart if it receives a -HUP (hangup) signal. On receiving this type of signal, the server stops and immediately restarts, rereading its configuration files.

<BR>

<P>Here's the listing for the restart script:

<BR>

<PRE>

<FONT COLOR="#000080">#!/bin/sh

#Restart Apache Script

kill -HUP 'cat /usr/local/etc/httpd/logs/httpd.pid'</FONT></PRE>

<P>This is a very convenient script that automates the process. Any time you modify any of the configuration files, you need to restart the server to enable the changes. htrestart makes this easy to do.

<BR>

<BR>

<A NAME="E69E13"></A>

<H4 ALIGN=CENTER>

<CENTER>

<FONT SIZE=4 COLOR="#FF0000"><B>Auto-Starting the Web Server at Boot Time</B></FONT></CENTER></H4>

<BR>

<P>You may be interested in automating the startup process of the server whenever you boot your machine. Doing so is very easy. On your /etc/rc.local file, add an entry like this:

<BR>

<PRE>

<FONT COLOR="#000080">#

# Run httpd server automatically

#

echo 'starting httpd server'

if [ -f /etc/rc.httpd ]; then

 sh /etc/rc.httpd

fi</FONT></PRE>

<P>Create a new file, /etc/rc.httpd, with the following contents:

<BR>

<PRE>

<FONT COLOR="#000080">#!/bin/sh -u

#

cd /usr/local/etc/httpd/

./httpd -d /usr/local/etc/httpd/ -f conf/httpd.conf</FONT></PRE>

<P>Although you can put the commands in /etc/rc.httpd in your /etc/rc.local, I find it convenient to be able to disable the server from loading by renaming the /etc/rc.httpd. When the computer boots, if /etc/rc finds a file named /etc/rc.httpd, it will execute the commands it finds there.

<BR>

<BR>

<A NAME="E68E21"></A>

<H3 ALIGN=CENTER>

<CENTER>

<FONT SIZE=5 COLOR="#FF0000"><B>Testing the Newly Installed Server</B></FONT></CENTER></H3>

<BR>

<P>If your configuration files were edited properly, you should be able to point your Web browser to the machine running the server and see the page you created earlier, confirming that your server is running. Figure 2.2 shows what your screen should look like.

<BR>

<P><A NAME="I16"></A><A NAME="I17"></A><A NAME="I18"></A><A NAME="I19"></A><A NAME="I20"></A><A NAME="I21"></A><B> <A HREF="javascript:if(confirm('http://docs.rinet.ru:8080/Apachu/02asg02.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/02asg02.gif'" tppabs="http://docs.rinet.ru:8080/Apachu/02asg02.gif">Figure 2.3. The startup page you created as </B><B>rendered by Microsoft Internet Explorer version 3.0</B><B>.</A></B>

<BR>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -