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

📄 network-apache.html

📁 这是很好的学习嵌入式LINUX的文章
💻 HTML
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta name="generator" content="HTML Tidy, see www.w3.org" /><title>Apache HTTP Server</title><meta name="GENERATOR" content="Modular DocBook HTML Stylesheet Version 1.7" /><link rel="HOME" title="FreeBSD 使用手册" href="index.html" /><link rel="UP" title="Network Servers" href="network-servers.html" /><link rel="PREVIOUS" title="Domain Name System (DNS)" href="network-dns.html" /><link rel="NEXT" title="File Transfer Protocol (FTP)" href="network-ftp.html" /><link rel="STYLESHEET" type="text/css" href="docbook.css" /><meta http-equiv="Content-Type" content="text/html; charset=GB2312" /></head><body class="SECT1" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#840084"alink="#0000FF"><div class="NAVHEADER"><table summary="Header navigation table" width="100%" border="0" cellpadding="0"cellspacing="0"><tr><th colspan="3" align="center">FreeBSD 使用手册</th></tr><tr><td width="10%" align="left" valign="bottom"><a href="network-dns.html"accesskey="P">后退</a></td><td width="80%" align="center" valign="bottom">章 23. Network Servers</td><td width="10%" align="right" valign="bottom"><a href="network-ftp.html"accesskey="N">前进</a></td></tr></table><hr align="LEFT" width="100%" /></div><div class="SECT1"><h1 class="SECT1"><a id="NETWORK-APACHE" name="NETWORK-APACHE">23.7. Apache HTTPServer</a></h1><i class="AUTHORGROUP"><span class="CONTRIB">Contributed by</span> Murray Stokely.</i> <div class="SECT2"><h2 class="SECT2"><a id="AEN34745" name="AEN34745">23.7.1. Overview</a></h2><p>FreeBSD is used to run some of the busiest web sites in the world. The majority of webservers on the Internet are using the <b class="APPLICATION">Apache HTTP Server</b>. <bclass="APPLICATION">Apache</b> software packages should be included on your FreeBSDinstallation media. If you did not install <b class="APPLICATION">Apache</b> when youfirst installed FreeBSD, then you can install it from the <ahref="http://www.FreeBSD.org/cgi/url.cgi?ports/www/apache13/pkg-descr"><ttclass="FILENAME">www/apache13</tt></a> or <ahref="http://www.FreeBSD.org/cgi/url.cgi?ports/www/apache2/pkg-descr"><ttclass="FILENAME">www/apache2</tt></a> port.</p><p>Once <b class="APPLICATION">Apache</b> has been installed successfully, it must beconfigured.</p><div class="NOTE"><blockquote class="NOTE"><p><b>注:</b> This section covers version 1.3.X of the <b class="APPLICATION">Apache HTTPServer</b> as that is the most widely used version for FreeBSD. <bclass="APPLICATION">Apache&nbsp;2.X</b> introduces many new technologies but they are notdiscussed here. For more information about <b class="APPLICATION">Apache&nbsp;2.X</b>,please see <a href="http://httpd.apache.org/"target="_top">http://httpd.apache.org/</a>.</p></blockquote></div></div><div class="SECT2"><h2 class="SECT2"><a id="AEN34761" name="AEN34761">23.7.2. Configuration</a></h2><p>The main <b class="APPLICATION">Apache HTTP Server</b> configuration file is installedas <tt class="FILENAME">/usr/local/etc/apache/httpd.conf</tt> on FreeBSD. This file is atypical <span class="TRADEMARK">UNIX</span>&reg; text configuration file with commentlines beginning with the <var class="LITERAL">#</var> character. A comprehensivedescription of all possible configuration options is outside the scope of this book, soonly the most frequently modified directives will be described here.</p><div class="VARIABLELIST"><dl><dt><var class="LITERAL">ServerRoot "/usr/local"</var></dt><dd><p>This specifies the default directory hierarchy for the <bclass="APPLICATION">Apache</b> installation. Binaries are stored in the <ttclass="FILENAME">bin</tt> and <tt class="FILENAME">sbin</tt> subdirectories of the serverroot, and configuration files are stored in <tt class="FILENAME">etc/apache</tt>.</p></dd><dt><var class="LITERAL">ServerAdmin you@your.address</var></dt><dd><p>The address to which problems with the server should be emailed. This address appearson some server-generated pages, such as error documents.</p></dd><dt><var class="LITERAL">ServerName www.example.com</var></dt><dd><p><var class="LITERAL">ServerName</var> allows you to set a host name which is sent backto clients for your server if it is different to the one that the host is configured with(i.e., use <tt class="HOSTID">www</tt> instead of the host's real name).</p></dd><dt><var class="LITERAL">DocumentRoot "/usr/local/www/data"</var></dt><dd><p><var class="LITERAL">DocumentRoot</var>: The directory out of which you will serveyour documents. By default, all requests are taken from this directory, but symboliclinks and aliases may be used to point to other locations.</p></dd></dl></div><p>It is always a good idea to make backup copies of your <bclass="APPLICATION">Apache</b> configuration file before making changes. Once you aresatisfied with your initial configuration you are ready to start running <bclass="APPLICATION">Apache</b>.</p></div><div class="SECT2"><h2 class="SECT2"><a id="AEN34802" name="AEN34802">23.7.3. Running <bclass="APPLICATION">Apache</b></a></h2><p><b class="APPLICATION">Apache</b> does not run from the <bclass="APPLICATION">inetd</b> super server as many other network servers do. It isconfigured to run standalone for better performance for incoming HTTP requests fromclient web browsers. A shell script wrapper is included to make starting, stopping, andrestarting the server as simple as possible. To start up <bclass="APPLICATION">Apache</b> for the first time, just run:</p><pre class="SCREEN"><samp class="PROMPT">#</samp> <kbdclass="USERINPUT">/usr/local/sbin/apachectl start</kbd></pre><p>You can stop the server at any time by typing :</p><pre class="SCREEN"><samp class="PROMPT">#</samp> <kbd class="USERINPUT">/usr/local/sbin/apachectl stop</kbd></pre><p>After making changes to the configuration file for any reason, you will need torestart the server:</p><pre class="SCREEN"><samp class="PROMPT">#</samp> <kbdclass="USERINPUT">/usr/local/sbin/apachectl restart</kbd></pre><p>To launch <b class="APPLICATION">Apache</b> at system startup, add the following lineto <tt class="FILENAME">/etc/rc.conf</tt>:</p><pre class="PROGRAMLISTING">apache_enable="YES"</pre><p>If you would like to supply additional command line options for the <bclass="APPLICATION">Apache</b> <tt class="COMMAND">httpd</tt> program started at systemboot, you may specify them with an additional line in <ttclass="FILENAME">rc.conf</tt>:</p><pre class="PROGRAMLISTING">apache_flags=""</pre><p>Now that the web server is running, you can view your web site by pointing a webbrowser to <var class="LITERAL">http://localhost/</var>. The default web page that isdisplayed is <tt class="FILENAME">/usr/local/www/data/index.html</tt>.</p></div><div class="SECT2"><h2 class="SECT2"><a id="AEN34835" name="AEN34835">23.7.4. Virtual Hosting</a></h2><p><b class="APPLICATION">Apache</b> supports two different types of Virtual Hosting. Thefirst method is Name-based Virtual Hosting. Name-based virtual hosting uses the clientsHTTP/1.1 headers to figure out the hostname. This allows many different domains to sharethe same IP address.</p><p>To setup <b class="APPLICATION">Apache</b> to use Name-based Virtual Hosting add anentry like the following to your <tt class="FILENAME">httpd.conf</tt>:</p><pre class="PROGRAMLISTING">NameVirtualHost *</pre><p>If your webserver was named <tt class="HOSTID">www.domain.tld</tt> and you wanted tosetup a virtual domain for <tt class="HOSTID">www.someotherdomain.tld</tt> then you wouldadd the following entries to <tt class="FILENAME">httpd.conf</tt>:</p><pre class="SCREEN">&lt;VirtualHost *&gt;ServerName www.domain.tldDocumentRoot /www/domain.tld&lt;VirtualHost&gt;&lt;VirtualHost *&gt;ServerName www.someotherdomain.tldDocumentRoot /www/someotherdomain.tld&lt;/VirtualHost&gt;</pre><p>Replace the addresses with the addresses you want to use and the path to the documentswith what you are using.</p><p>For more information about setting up virtual hosts, please consult the official <bclass="APPLICATION">Apache</b> documentation at: <ahref="http://httpd.apache.org/docs/vhosts/"target="_top">http://httpd.apache.org/docs/vhosts/</a></p></div><div class="SECT2"><h2 class="SECT2"><a id="AEN34852" name="AEN34852">23.7.5. Apache Modules</a></h2><p>There are many different <b class="APPLICATION">Apache</b> modules available to addfunctionality to the basic server. The FreeBSD Ports Collection provides an easy way toinstall <b class="APPLICATION">Apache</b> together with some of the more popular add-onmodules.</p><div class="SECT3"><h3 class="SECT3"><a id="AEN34860" name="AEN34860">23.7.5.1. mod_ssl</a></h3><p>The <b class="APPLICATION">mod_ssl</b> module uses the OpenSSL library to providestrong cryptography via the Secure Sockets Layer (SSL v2/v3) and Transport Layer Security(TLS v1) protocols. This module provides everything necessary to request a signedcertificate from a trusted certificate signing authority so that you can run a secure webserver on FreeBSD.</p><p>If you have not yet installed <b class="APPLICATION">Apache</b>, then a version of <bclass="APPLICATION">Apache</b> that includes <b class="APPLICATION">mod_ssl</b> may beinstalled with the <ahref="http://www.FreeBSD.org/cgi/url.cgi?ports/www/apache13-modssl/pkg-descr"><ttclass="FILENAME">www/apache13-modssl</tt></a> port.</p></div><div class="SECT3"><h3 class="SECT3"><a id="AEN34876" name="AEN34876">23.7.5.2. mod_perl</a></h3><p>The <b class="APPLICATION">Apache</b>/Perl integration project brings together thefull power of the Perl programming language and the <b class="APPLICATION">Apache HTTPServer</b>. With the <b class="APPLICATION">mod_perl</b> module it is possible to write<b class="APPLICATION">Apache</b> modules entirely in Perl. In addition, the persistentinterpreter embedded in the server avoids the overhead of starting an externalinterpreter and the penalty of Perl start-up time.</p><p>If you have not yet installed <b class="APPLICATION">Apache</b>, then a version of <bclass="APPLICATION">Apache</b> that includes <b class="APPLICATION">mod_perl</b> may beinstalled with the <ahref="http://www.FreeBSD.org/cgi/url.cgi?ports/www/apache13-modperl/pkg-descr"><ttclass="FILENAME">www/apache13-modperl</tt></a> port.</p></div><div class="SECT3"><h3 class="SECT3"><a id="AEN34890" name="AEN34890">23.7.5.3. PHP</a></h3><p>PHP, which stands for ``PHP: Hypertext Preprocessor'' is a widely-used Open Sourcegeneral-purpose scripting language that is especially suited for Web development and canbe embedded into HTML. Its syntax draws upon C, <spanclass="TRADEMARK">Java</span>&#8482;, and Perl, and is easy to learn. The main goal ofthe language is to allow web developers to write dynamically generated webpages quickly,but you can do much more with PHP.</p><p>PHP may be installed from the <ahref="http://www.FreeBSD.org/cgi/url.cgi?ports/lang/php5/pkg-descr"><ttclass="FILENAME">lang/php5</tt></a> port.</p></div></div></div><div class="NAVFOOTER"><hr align="LEFT" width="100%" /><table summary="Footer navigation table" width="100%" border="0" cellpadding="0"cellspacing="0"><tr><td width="33%" align="left" valign="top"><a href="network-dns.html"accesskey="P">后退</a></td><td width="34%" align="center" valign="top"><a href="index.html"accesskey="H">起点</a></td><td width="33%" align="right" valign="top"><a href="network-ftp.html"accesskey="N">前进</a></td></tr><tr><td width="33%" align="left" valign="top">Domain Name System (DNS)</td><td width="34%" align="center" valign="top"><a href="network-servers.html"accesskey="U">上一级</a></td><td width="33%" align="right" valign="top">File Transfer Protocol (FTP)</td></tr></table></div></body></html>

⌨️ 快捷键说明

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