海鷗航際

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

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

          二、軟件的相關(guān)資源

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

          1.安裝

          由其官方網(wǎng)站中下載其源碼軟件包httpd-2.0.53.tar.gz。接下來(lái)我將對(duì)安裝過(guò)程的一些重要步驟,給出其解釋:

          [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 針對(duì)機(jī)器作安裝的檢查和設(shè)置,大部分的工作是由機(jī)器自動(dòng)完成的,但是用戶可以通過(guò)一些參數(shù)來(lái)完成一定的設(shè)置,其常用選項(xiàng)有:

          ./configure --help 察看參數(shù)設(shè)置幫助。

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

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

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

          可以設(shè)置的參數(shù)很多,可以通過(guò) -help察看需要的,一般情況下,默認(rèn)設(shè)置就可以了。

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

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

          /usr/local/apache2/conf 其中主要是服務(wù)器相關(guān)的配置文件。最主要的配置文件是httpd.conf。

          /usr/local/apache2/htdocs 默認(rèn)的網(wǎng)站html文件根目錄。

          /usr/local/apache2/cgi-bin 默認(rèn)的cgi程序的存放目錄。

          2.啟動(dòng):

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


          如果不出什么問(wèn)題,ps aux 應(yīng)該可以查到httpd 的進(jìn)程,或netstat -an 也可以看到80端口的服務(wù)已經(jīng)起來(lái)了。如果要設(shè)置開(kāi)機(jī)自啟動(dòng)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 默認(rèn)安裝,所有的配置都有其默認(rèn)值,接下來(lái)我介紹介紹一些常用的配置項(xiàng):









          # 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


          設(shè)定apache 的偵聽(tīng)地址和端口。

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


          設(shè)定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"


          設(shè)定apache web server 的文檔根目錄,必須是絕對(duì)路徑。

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


          設(shè)定文檔根目錄的權(quán)限控制,必須和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的根目錄,必須是絕對(duì)路徑。

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


          設(shè)定cgi-bin目錄的讀寫(xiě)權(quán)限,該目錄項(xiàng)必須和上一條的設(shè)置一致。

          五.安裝使用的一些經(jīng)驗(yàn):

          1.apache 進(jìn)程的有效用戶id默認(rèn)為nobody。

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

          2.如果網(wǎng)站的訪問(wèn)量不是很大可以考慮用xinetd超級(jí)進(jìn)程來(lái)啟動(dòng)apache

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

          ServerType inetd


          (2)創(chuàng)建/etc/xinetd.d/apache,內(nèi)容:

          # 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)重新啟動(dòng)xinetd:

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


          3.對(duì)IPV6的支持

          隨著計(jì)算機(jī)網(wǎng)絡(luò)的不斷發(fā)展和擴(kuò)大,IPV6已經(jīng)越來(lái)越為人們所接受,apache自2.0之后的版本開(kāi)始支持IPV6,下面我就簡(jiǎn)單介紹一下apache針對(duì)ipv6的配置:

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

          Listen 80


          要使apache 區(qū)別對(duì)待IPV4與IPV6的連接,安裝配置時(shí),使用 ./configure -disable-v4-map , 對(duì)應(yīng)配置文件中http.conf :

          Listen [::]:80


          這樣 apache 就可以區(qū)別對(duì)待 IPV4 與IPV6的連接了。
          主站蜘蛛池模板: 建宁县| 宁安市| 花莲市| 邵阳县| 湾仔区| 安泽县| 三原县| 兴国县| 三江| 丹阳市| 柘荣县| 韶山市| 宜君县| 谢通门县| 乌鲁木齐县| 若尔盖县| 永顺县| 遂溪县| 三明市| 克拉玛依市| 磐安县| 乌鲁木齐市| 桃江县| 洞头县| 龙里县| 宜昌市| 滦平县| 得荣县| 永康市| 华坪县| 二连浩特市| 安宁市| 库伦旗| 平邑县| 彩票| 海兴县| 新巴尔虎左旗| 龙陵县| 周至县| 巧家县| 金堂县|