歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux綜合 >> Linux資訊 >> Linux文化 >> 教你在Redhat 上搭建 Apache 服務器

教你在Redhat 上搭建 Apache 服務器

日期:2017/2/27 11:58:26   编辑:Linux文化

一. Apache介紹

Apache HTTP服務器是現在互連網上最流行的Web服務器. 眾所周知, 它的

最早版本是於1995年12月1日發布的. 最初的Apache版本是由美國伊利諾斯

大學香槟分校(University of Illinios, Urbana-Champaign.)國家超級

計算應用中心(NCSA)的Rob McCool先生開發的the Public Domain HTTPS

Daemon程序發展而來. 它具有強大的功能, 如基於名字和IP地址的虛擬主機,

用戶驗證, URL重定向(URL Rewrite), SSI(服務器端嵌入), SSL(安全套接層)

等更多.

提示:

互連網上大概有65%的Web服務器使用Apache HTTP服務器. 這個數字是通過

Netcraft網站了解的. 如果您對互連網上Web服務器調查報告感興趣的話,

可以訪問以下的網址:

http://news.netcraft.com/archives/web_server_survey.html

現在最新的數據是: Apache (68.4%), Microsoft (20.9 %), 其它(10.7 %).

查詢時間: 2004-01-31 11:34 北京時間

二. Apache HTTP版本的選擇

現在Apache HTTP有兩種版本系列: Apache 1.3 或 Apache 2.0

如何選擇版本? 簡而言之, Apache 1.3系列的版本強調是穩定性; Apache 2.0

強調的是新功能的支持.

Apache 1.3新的功能:

http://httpd.apache.org/docs/new_features_1_3.html

Apache 2.0新的功能:

http://httpd.apache.org/docs-2.0/new_features_2_0.html (英文)

https://support.iap.ac.cn/net/ApacheManual/zh-cn/ (中文)

本文中使用的是Apache 1.3.3版本.

三. 准備工作

說明:

所有的命令行操作使用的是root用戶.

Apache軟件包是源文件的發布形式.

Shell命令環境中#表示當前用戶權限為root,

$表示當前擁護權限為普通用戶.

1. 移去已經安裝的Apache HTTP Server RPMs包.

如果您的系統沒有安裝過Apache, 請參考步驟2.

1) 查詢跟httpd相依賴的軟件包.

#rpm -q --whatrequires httpd

說明:

2) 從系統中移去以下的軟件包.

#rpm -e redhat-config-httpd

#rpm -e httpd

3) 查詢是否存在httpd進程, 如有, 用killall命令終止httpd進程.

#ps aux|grep httpd

#killall httpd

2. 下載和解壓縮Apache HTTP軟件包.

建議從apache的官方網站獲得可靠的apache HTTP軟件包.

下載網址: http://httpd.apache.org/download.cgi

1) 創建apache軟件包存放的目錄.

#mkdir -p /usr/local/src/webserver

2) 使用wget命令獲得源代碼包.

#wget http://apache.tarchive.com/httpd/apache_1.3.33.tar.gz

3) 解壓縮源代碼包, 在webserver目錄下會生成一個新的目錄apache_1.3.33

#tar zpxf apache_1.3.33.tar.gz

四. 安裝Apache Web Server 1.3.3

這裡我使用的是DSO(Dynamic Shared Objects)的方式來安裝Apache HTTP服務器.

使用DSO的安裝方式允許您在以後不需要重新編譯Apache的情況下添加模塊.

如PHP等等.

1) 創建安裝腳本apache_inst.

#cd /usr/local/src/webserver

#vi apache_inst

---拷貝下面區域內容然後張貼到apache_inst中--

cd /usr/local/src/webserver/apache_1.3.33

./configure \

--prefix=/www \

--enable-module=so \

--enable-module=rewrite \

--enable-shared=rewrite \

--enable-module=setenvif \

--enable-shared=setenvif \

--enable-module=mime \

--enable-shared=mime \

--enable-module=mime_magic \

--enable-shared=mime_magic \

--enable-module=dir \

--enable-shared=dir \

--enable-module=auth \

--enable-shared=auth \

--enable-module=access \

--enable-shared=access \

--enable-module=alias \

--enable-shared=alias \

--enable-module=status \

--enable-shared=status \

--enable-module=userdir \

--enable-shared=userdir \

--enable-module=env \

--enable-shared=env \

--enable-module=log_referer \

--enable-shared=log_referer \

--enable-module=log_config \

--enable-shared=log_config \

--enable-module=log_agent \

--enable-shared=log_agent \

--enable-module=headers \

--enable-shared=headers

------------------結束----------------------

#chmod +x apache_inst

說明: 設置apache_inst文件的可執行權限.

2) 執行安裝腳本apache_inst.

#./apache_inst

3) 到源代碼文件所在目錄編譯和安裝Apache Web Server.

#cd /usr/local/src/webserver/apache_1.3.33

#make

#make install

4) 創建apache控制命令的軟鏈接.

#ln -s /www/bin/apachectl /usr/bin/apachectl

#ln -s /www/bin/apachectl /usr/sbin/apachectl

5) 運行Apache Web服務器.

#apachectl start

相關:

#apachectl start 啟動apache.

#apachectl stop 停止apache.

#apachectl restart 重新啟動apache.

#apachectl status 顯示apache的狀態.

#apachectl configtest 測試httpd.conf配置是否正確.

6) 讓系統啟動時自動運行Apache Web服務器.

#vi /etc/rc.d/rc.local

說明: 在rc.local文件最後添加下面一行.

apachectl start

五. 測試Apache Web服務器是否運行.

您可以在浏覽器中通過機器的主機名或者IP地址以http://yourdomain.com

或者http://192.168.0.1(此出輸入您機器的IP地址)訪問Web服務. 您將會

看到一個成功安裝Apache HTTP服務器的臨時網頁.

六. Apache HTTP的安裝目錄

Apache HTTP服務器到此已經安裝到系統中, 安裝的目錄是/www. 接下來

了解每一個目錄的用途:

/www 也叫ServerRoot, 用於放置所有安裝後的Apache相關文件.

/www/bin 用於放置apache的運行程序.

/www/cgi-bin 缺省用於運行如perl腳本的cgi-bin目錄.

/www/conf 用於放置所有的配置文件如httpd.conf等.

/www/htdocs Apache Web服務器的Document Root目錄. htdocs這裡全稱

是http documentations, 即用於存放web網頁.

/www/icons 用於放置Apache Web服務器的圖標. 如Directory

Listing用到的圖標.

/www/includes 用於放置運行Apache Web服務器用到的頭文件.

/www/libexec 用於放置您在安裝編譯時候用到的模塊.

/www/logs 缺省用於放置Apache Web服務器運行的所有活動日志.

/www/man 用於放置幫助文件.

/www/proxy 用於配置proxy相關內容.

七. Apache HTTP的配置文件

Apache配置文件為httpd.conf, 所在目錄/conf, 這裡我只對本文apache用

的httpd.conf文件列出一個清單.更多信息的httpd.conf文件指令解釋請

參考網上相關內容.

ServerType standalone

ServerRoot "/www"

PidFile /www/log/httpd.pid

ScoreBoardFile /www/logs/httpd.scoreboard

Timeout 300

KeepAlive On

MaxKeepAliveRequests 100

KeepAliveTimeout 15

MinSpareServers 5

MaxSpareServers 10

StartServers 5

MaxClients 150

MaxRequestPerChild 0

LISTEN 210.77.144.83:80

BindAddress *

LoadModule name file

AddModule header file name

Port 80

User nobody

Group nobody

ServerAdmin [email protected]

ServerName www.islab.org

DocumentRoot "/www/htdocs"

Directory

UserDir

DirectoryIndex files

DirectoryIndex index.html

AccessFileName .htaccess

Order allow,deny

Deny from all

Satisfy All

UseCanonicalName On

TypesConfig

TypesConfig /www/conf/mime.types

DefaultType text/plain

MIMEMagicFile /www/conf/magic

MIMEMagicFile /www/conf/magic

HostnameLookups Off

ErrorLog /www/logs/error_log

LogLevel warn

LogFormat

CustomLog /www/logs/access_log common

ServerSignature On

Alias /icons/ "/www/icons/"

ScriptAlias /cgi-bin/ "/www/cgi-bin/"

IndexOptions FancyIndexing

NameVitualHost *

VirtualHost

Copyright © Linux教程網 All Rights Reserved