海鷗航際

          JAVA站
          posts - 11, comments - 53, trackbacks - 1, articles - 102
          一.、Apache web server 簡介

          Apache web server是一款開放源碼的web服務器軟件,由apache software foundation 開發和維護的。它是目前世界上使用最為廣泛的web服務器軟件,支持各種unix平臺和windows平臺。本文將介紹它在Red hat Linux 9中最基本的安裝和配置。

          二、軟件的相關資源

          官方網站:http://httpd.apache.org/
          源碼軟件包:Apache 是開源的軟件,可以去其官方網站http://httpd.apache.org/download.cgi下載。目前的最新穩定版本是httpd-2.0.53。
          幫助文檔:http://httpd.apache.org/docs-project/ 有該軟件比較全面的幫助文檔。
          FAQ:http://httpd.apache.org/docs/misc/FAQ.html 回答了該軟件的常見問題。
          三.軟件的安裝

          1.安裝

          由其官方網站中下載其源碼軟件包httpd-2.0.53.tar.gz。接下來我將對安裝過程的一些重要步驟,給出其解釋:

          [root@localhost root]#tar xzvf httpd-2.0.53.tar.gz
          [root@localhost root]#cd httpd-2.0.53
          [root@localhost httpd-2.0.53]#./configure
          [root@localhost httpd-2.0.53]#make
          [root@localhost httpd-2.0.53]#make install


          tar xzvf httpd-2.0.53.tar.gz 解壓縮軟件包。

          ./configure 針對機器作安裝的檢查和設置,大部分的工作是由機器自動完成的,但是用戶可以通過一些參數來完成一定的設置,其常用選項有:

          ./configure --help 察看參數設置幫助。

          --prefix= 指定軟件安裝目錄(默認/usr/local/apache2)。

          --enable-modules= 指定需要加載的模塊。

          --enable-v4-mapped 支持ipv6的socket處理ipv4的連接。

          可以設置的參數很多,可以通過 -help察看需要的,一般情況下,默認設置就可以了。

          默認安裝建立了/usr/local/apache2目錄,下面介紹一下/usr/local/apache2的幾個常用組成部分:

          /usr/local/apache2/bin 其中主要是有服務器的程序。常用的有deamon程序httpd,和控制腳本apachectl。

          /usr/local/apache2/conf 其中主要是服務器相關的配置文件。最主要的配置文件是httpd.conf。

          /usr/local/apache2/htdocs 默認的網站html文件根目錄。

          /usr/local/apache2/cgi-bin 默認的cgi程序的存放目錄。

          2.啟動:

          [root@localhost root]# /usr/local/apache2/bin/apachectl start
          [root@localhost root]# ps aux 
          [root@localhost root]# netstat -an


          如果不出什么問題,ps aux 應該可以查到httpd 的進程,或netstat -an 也可以看到80端口的服務已經起來了。如果要設置開機自啟動web server,只需在/etc/rc.d/rc.local中加入一行

          /usr/local/apache2/bin/apachectl start

          #!/bin/sh
          #
          # This script will be executed *after* all the other init scripts.
          # You can put your own initialization stuff in here if you don't
          # want to do the full Sys V style init stuff.
          touch /var/lock/subsys/local
          
          /usr/local/apache2/bin/apachectl start

          四、軟件的配置。

          /usr/local/apache2/conf/httpd.conf 默認安裝,所有的配置都有其默認值,接下來我介紹介紹一些常用的配置項:









          # Listen: Allows you to bind Apache to specific IP addresses and/or
          # ports, instead of the default. See also the <VirtualHost>
          # directive.
          #
          # Change this to Listen on specific IP addresses as shown below to
          # prevent Apache from glomming onto all bound IP addresses (0.0.0.0)
          #
          #Listen 12.34.56.78:80
          
          Listen 80


          設定apache 的偵聽地址和端口。

          #
          # ServerAdmin: Your address, where problems with the server should be
          # e-mailed.  This address appears on some server-generated pages, such
          # as error documents.  e.g. admin@your-domain.com
          #
          ServerAdmin you@example.com


          設定apache 的管理員郵件地址。

          #
          # DocumentRoot: The directory out of which you will serve your
          # documents. By default, all requests are taken from this directory, but
          # symbolic links and aliases may be used to point to other locations.
          #
          DocumentRoot "/usr/local/apache2/htdocs"


          設定apache web server 的文檔根目錄,必須是絕對路徑。

          <Directory "/usr/local/apache2/htdocs">
          
          #
          # Possible values for the Options directive are "None", "All",
          # or any combination of:
          #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
          #
          # Note that "MultiViews" must be named *explicitly* --- "Options All"
          # doesn't give it to you.
          #
          # The Options directive is both complicated and important.  Please see
          # http://httpd.apache.org/docs-2.0/mod/core.html#options
          # for more information.
          #
              Options Indexes FollowSymLinks
          
          #
          # AllowOverride controls what directives may be placed in .htaccess files.
          # It can be "All", "None", or any combination of the keywords:
          #   Options FileInfo AuthConfig Limit
          #
              AllowOverride None
          
          #
          # Controls who can get stuff from this server.
          #
              Order allow,deny
              Allow from all
          
          </Directory>


          設定文檔根目錄的權限控制,必須和DocumentRoot "/usr/local/apache2/htdocs" 中指定的目錄一致。

          #
          # The index.html.var file (a type-map) is used to deliver content-
          # negotiated documents.  The MultiViews Option can be used for the
          # same purpose, but it is much slower.
          #
          DirectoryIndex index.html


          指定該目錄下的索引文檔,

          ScriptAlias /cgi-bin/ "/usr/local/apache2/cgi-bin/"


          映射cgi-bin的根目錄,必須是絕對路徑。

          <Directory "/usr/local/apache2/cgi-bin">
              AllowOverride None
              Options None
              Order allow,deny
              Allow from all
          </Directory>


          設定cgi-bin目錄的讀寫權限,該目錄項必須和上一條的設置一致。

          五.安裝使用的一些經驗:

          1.apache 進程的有效用戶id默認為nobody。

          出于安全方面的考慮,apache 服務器進程的默認有效 id 被設置為nobody,這就意味著該進程只擁有nobody的權限,所以必須確保nobody對設置的DocumentRoot 有足夠權限。或者可以配置apache進程的有效id,但是推薦不要這樣做。

          2.如果網站的訪問量不是很大可以考慮用xinetd超級進程來啟動apache

          (1)打開/usr/local/apache2/conf/httpd.conf,修改

          ServerType inetd


          (2)創建/etc/xinetd.d/apache,內容:

          # default: on
          # description: The Apache HTTP connections.
          service http
          {
          disable = no
          socket_type = stream
          wait = no
          user = root
          server = /usr/sbin/httpd
          port = 80
          # log_on_success += DURATION USERID
          # log_on_failure += USERID
          # nice = 10
          }


          (3)重新啟動xinetd:

          #/etc/rc.d/init.d/xinetd restart


          3.對IPV6的支持

          隨著計算機網絡的不斷發展和擴大,IPV6已經越來越為人們所接受,apache自2.0之后的版本開始支持IPV6,下面我就簡單介紹一下apache針對ipv6的配置:

          默認情況下,apache 使用映射到IPv4的IPv6地址,即安裝配置時,默認./configure -enable-v4-map ,并且在配置文件http.conf中將是:

          Listen 80


          要使apache 區別對待IPV4與IPV6的連接,安裝配置時,使用 ./configure -disable-v4-map , 對應配置文件中http.conf :

          Listen [::]:80


          這樣 apache 就可以區別對待 IPV4 與IPV6的連接了。
          主站蜘蛛池模板: 张掖市| 乌兰察布市| 弥勒县| 湖北省| 佛山市| 九寨沟县| 乐亭县| 图们市| 烟台市| 盐亭县| 曲阜市| 双牌县| 新密市| 长海县| 高阳县| 渭源县| 麻城市| 社旗县| 奉贤区| 馆陶县| 河南省| 闵行区| 察雅县| 满城县| 樟树市| 革吉县| 昌平区| 独山县| 夏河县| 吉林市| 松溪县| 巴中市| 临泽县| 军事| 武邑县| 杭锦旗| 基隆市| 尉犁县| 东兴市| 丘北县| 宜丰县|