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

📄 ch01_04.htm

📁 用perl编写CGI的好书。本书从解释CGI和底层HTTP协议如何工作开始
💻 HTM
📖 第 1 页 / 共 2 页
字号:
<?label 1.4. Web Server Configuration?><html><head><title>Web Server Configuration (CGI Programming with Perl)</title><link href="../style/style1.css" type="text/css" rel="stylesheet" /><meta name="DC.Creator" content="Scott Guelich, Gunther Birznieks and Shishir Gundavaram" /><meta scheme="MIME" content="text/xml" name="DC.Format" /><meta content="en-US" name="DC.Language" /><meta content="O'Reilly & Associates, Inc." name="DC.Publisher" /><meta scheme="ISBN" name="DC.Source" content="1565924193L" /><meta name="DC.Subject.Keyword" content="stuff" /><meta name="DC.Title" content="CGI Programming with Perl" /><meta content="Text.Monograph" name="DC.Type" /></head><body bgcolor="#ffffff"><img src="gifs/smbanner.gif" alt="Book Home" usemap="#banner-map" border="0" /><map name="banner-map"><area alt="CGI Programming with Perl" href="index.htm" coords="0,0,466,65" shape="rect" /><area alt="Search this book" href="jobjects/fsearch.htm" coords="467,0,514,18" shape="rect" /></map><div class="navbar"><table border="0" width="515"><tr><td width="172" valign="top" align="left"><a href="ch01_03.htm"><img src="../gifs/txtpreva.gif" alt="Previous" border="0" /></a></td><td width="171" valign="top" align="center"><a href="index.htm">CGI Programming with Perl</a></td><td width="172" valign="top" align="right"><a href="ch02_01.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0" /></a></td></tr></table></div><hr align="left" width="515" /><h2 class="sect1">1.4. Web Server Configuration</h2><p>Before <a name="INDEX-125" /> <a name="INDEX-126" /> <a name="INDEX-127" />you can run CGIprograms on your server, certain parameters in the serverconfiguration files must be modified. Throughout this book, we willuse the <a name="INDEX-128" />Apache web server on a Unix platform inour examples. Apache is by far the most popular web server available,plus it's open source and available for free. Apache is derivedfrom the NCSA web server, so many configuration details for it aresimilar to those for other web servers that are also derived from theNCSA server, such as those sold by iPlanet (formerly Netscape).</p><p>We assume that you already have access to a working web server, so wewon't cover how to install and initially configure Apache. Thatlengthy discussion would be well beyond the scope of this book, andthat information is already available in another fine book,<em class="citetitle">Apache: The Definitive Guide,</em> by Ben and PeterLaurie (O'Reilly &amp; Associates, Inc.).</p><p>Apache is not always installed in the same place on all systems.Throughout this book, we will use the <a name="INDEX-129" /><a name="INDEX-130" /><a name="INDEX-131" />default installation path, whichplaces everything beneath <em class="filename">/usr/local/apache</em>.Apache's <a name="INDEX-132" />subdirectories are:</p><blockquote><pre class="code">$ cd /usr/local/apache$ ls -Fbin/  cgi-bin/  conf/  htdocs/  icons/  include/  libexec/  logs/  man/  proxy/</pre></blockquote><p>Depending on how Apache was configured during installation, you maynot have some directories, such as <em class="filename">libexec</em> or<em class="filename">proxy </em>; this is fine. With some popular Unix andUnix-compatible distributions that include Apache (e.g., some Linuxdistributions), the subdirectories above may be distributed acrossthe system instead. For example, on <a name="INDEX-133" />RedHat Linux, thesubdirectories are remapped, as shown in <a href="ch01_04.htm#ch01-24422">Table 1-1</a>.</p><a name="ch01-24422" /><h4 class="objtitle">Table 1-1. Alternative Paths to Important Apache Directories</h4><table border="1"><tr><th><p>Default Installation Path</p></th><th><p>Alternative Path (RedHat Linux)</p></th></tr><tr><td><p><em class="filename">/usr/local/apache/cgi-bin</em></p></td><td><p><em class="filename">/home/httpd/cgi-bin</em></p></td></tr><tr><td><p><em class="filename">/usr/local/apache/htdocs</em></p></td><td><p><em class="filename">/home/httpd/html</em></p></td></tr><tr><td><p><em class="filename">/usr/local/apache/conf</em></p></td><td><p><em class="filename">/etc/httpd/conf</em></p></td></tr><tr><td><p><em class="filename">/usr/local/apache/logs</em></p></td><td><p><em class="filename">/var/log/httpd</em></p></td></tr></table><p>If this is the case, you will need to translate our instructions tothe paths on your system. If Apache is installed on your system, andits directories are not at either of these locations, then ask yoursystem administrator or refer to your system documentation to locatethem.</p><p>You configure Apache by modifying the configuration files found inthe <em class="filename">conf</em> directory. These files containdirectives that Apache reads when it starts. Older versions of Apacheincluded three files: <em class="filename">httpd.conf</em>,<em class="filename">srm.conf</em>, and <em class="filename">access.conf</em>.However, using the latter two files was never required, and recentdistributions of Apache include all of the directives in<em class="filename">httpd.conf</em>. This allows you to manage the fullconfiguration in one location without bouncing between files. It alsoavoids situations where your configuration between files does notmatch, which can create security problems.</p><p>Many sites still use all three configuration files, if only becausethey have not bothered to combine them. Therefore, here andthroughout the book, whenever we discuss Apache configuration, wewill specify the alternative name of the file you need to edit if youare using all three files.</p><p>Finally, remember that Apache must be told to reread itsconfiguration files whenever you make changes to them. You do notneed to do a full server restart, although that also works. If yoursystem has the<tt class="command">apachectl</tt><a name="INDEX-134" /> command (part of thestandard install), you can tell Apache to reread its configurationwhile it is running with this command:</p><blockquote><pre class="code">$ apachectl graceful</pre></blockquote><p>This may require superuser (i.e., <em class="emphasis">root</em>)privileges.</p><a name="ch01-95149" /><div class="sect2"><h3 class="sect2">1.4.1. Configuring CGI Scripts</h3><p>Enabling <a name="INDEX-135" /><a name="INDEX-136" />CGI execution with Apache is very simple,although there is a good way to do it and a less good way to do it.Let's start with the good way, which involves creating aspecial <a name="INDEX-137" />directory for our CGI scripts.</p><a name="ch01-6-fm2xml" /><div class="sect3"><h3 class="sect3">1.4.1.1. Configuring by directory</h3><p>The <tt class="literal">ScriptAlias</tt><a name="INDEX-138" /><a name="INDEX-139" />directive tells the web server to map a <a name="INDEX-140" /> <a name="INDEX-141" /><a name="INDEX-142" />virtual path (the path in a URL) to adirectory on the disk and execute any files it finds there as CGIscripts.</p><p>To enable CGI scripts for our web server, place this directive in<em class="filename">httpd.conf </em>:</p><blockquote><pre class="code">ScriptAlias          /cgi        /usr/local/apache/cgi-bin</pre></blockquote><p>For example, if a user accesses the URL:</p><blockquote class="simplelist"><p><em class="emphasis">http://your_host.com/cgi/my_script.cgi</em></p></blockquote><p>then the local program:</p><blockquote><pre class="code">/usr/local/apache/cgi-bin/my_script.cgi</pre></blockquote><p>will be executed by the server. Note that the <em class="emphasis">cgi</em><a name="INDEX-143" /><a name="INDEX-144" /> path in the URL does not need to be thesame as the name of the filesystem directory,<em class="filename">cgi-bin</em><a name="INDEX-145" />. Whether you map the CGI directory to thevirtual path called <em class="emphasis">cgi</em>,<em class="emphasis">cgi-bin</em>, or anything else forthat matter, is strictly your own preference. You can also havemultiple directories hold CGI scripts if you need that feature:</p><blockquote><pre class="code">ScriptAlias          /cgi        /usr/local/apache/cgi-bin/ScriptAlias          /cgi2       /usr/local/apache/alt-cgi-bin/</pre></blockquote><p>The directory that holds CGI scripts must be outside theserver's document root. In a standard Apache install, the<a name="INDEX-146" />document<a name="INDEX-147" />root maps to the

⌨️ 快捷键说明

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