歡迎您光臨本站 註冊首頁

redhat enterprise linux 下 apache 服務的安裝與配置

←手機掃碼閱讀     火星人 @ 2014-03-09 , reply:0

apache伺服器是目前網際網路上最流行的web伺服器之一,它的開源性,是的軟體可以不斷的更新和升級,這樣安全性能也在不斷的提高,下面我們就來體驗一下red hat enterprise linux 下apache的搭建與配置.

1、apcahe服務安裝的前期準備

red hat 下 apache服務httpd 默認情況下是沒有被安裝的,如果你在安裝的時候沒有定製軟體的話.你可以通過以下命令來查詢你的機子上是否已經安裝了httpd服務.

# rpm -q httpd

如果給你返回沒有安裝此軟體的信息,那也沒事,安裝httpd服務很簡單.如果你有安裝光碟或者鏡像文件,你可以直接使用.在你掛載cdrom 或iso后,你可以去 /media/cdrom/Server/ 下尋找httpd相關的軟體包.相關的軟體包有:httpd、httpd-manual、httpd-tools等.當然你也直接去apache的官網上下載軟體包.

另外有一點需要我們注意,安裝httpd服務需要50MB的臨時磁碟空間,安裝后的apache服務需要佔用10MB左右的磁碟空間

安裝事例:

#rpm -ivh httpd-2.2.15-5.el6.i686.rpm

然後執行以下的命令啟動httpd服務:

#service httpd start

我們在客戶端瀏覽器中輸入伺服器的IP地址,如果可以進行訪問,恭喜你安裝成功了.

再補充兩個命令:

#service httpd restart /*重啟服務*/

#service httpd stop /*停止服務*/

2、讓apache伺服器開機自啟動:

圖形化界面中單擊“系統”—“管理”—“服務”,然後選擇httpd服務,如果是紅色的點將其點綠.

文字化界面中,我們可以 利用chkconfig命令來完成.

# chkconfig --level 2345 httpd on

如果是要關閉:

#chkconfig --level 2345 http off

3、apache服務的基本配置

apache的主配置文件是:/etc/httpd/conf/httpd.conf .注意:httpd.conf的配置語句除了選項的參數值以外,所有選項命令均不區分大小寫.

httpd.conf由3大部分構成:Global Environment(apache全局配置)、Main Server Configuration(主伺服器配置)、Virtual Hosts(虛擬主機配置).

介紹全局配置文件(### Section 1: Global Environment)

# (available at <URL:http://httpd.apache.org/docs/2.2/mod/mpm_common.html#lockfile>);

# you will save yourself a lot of trouble.

# Do NOT add a slash at the end of the directory path.

ServerRoot "/etc/httpd" //apache的根目錄:/etc/httpd ,該目錄下包括配置文件、記錄文件、模塊文件等.

# PidFile: The file in which the server should record its process

# identification number when it starts. Note the PIDFILE variable in

# /etc/sysconfig/httpd must be set appropriately if this location is

# changed.

PidFile run/httpd.pid // 在 /var/run/httpd.pid 保存著apache父進程的ID

# Timeout: The number of seconds before receives and sends time out.

Timeout 60 //超出時間控制,若客戶端超過60s還沒有連接上Server,或者Server超過60s還沒有傳送信息給客戶端,則強制斷線.

# KeepAlive: Whether or not to allow persistent connections (more than

# one request per connection). Set to "Off" to deactivate.

KeepAlive Off //表示不允許客戶端同時提出多個請求,on即可允許.

# MaxKeepAliveRequests: The maximum number of requests to allow

# during a persistent connection. Set to 0 to allow an unlimited amount.

# We recommend you leave this number high, for maximum performance.

MaxKeepAliveRequests 100 //表示每次聯繫允許的最大請求數目,數字越大,效率越高,0表示不受限制.

# KeepAliveTimeout: Number of seconds to wait for the next request from the

# same client on the same connection.

KeepAliveTimeout 15 //表示用戶端的請求如果15s沒有發出,則斷線.

## Server-Pool Size Regulation (MPM specific)

<IfModule prefork.c>

StartServers 8 //啟動時打開的httpd進程數目為8

MinSpareServers 5 //至少會有5個閑置的httpd進程來監聽用戶的請求

MaxSpareServers 20 //最多的閑置的httpd進程數為20 .如果網站的訪問量很大,可將這個數目設置大一些.

ServerLimit 256 //客戶端鏈接伺服器的最大生存時間.ttl值

MaxClients 256 //表示限制客戶端的同時最大連接數為256.一旦達到這個數目,客戶端就會備拒絕訪問.

MaxRequestsPerChild 4000 //表示限制每個httpd進程可以完成的最大任務數.

</IfModule>

# 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 //設置監聽埠 # Dynamic Shared Object (DSO) Support /*****/ //載入dso模塊,就像是windows中的dll(動態鏈接庫)

# ExtendedStatus controls whether Apache will generate "full" status # information (ExtendedStatus On) or just basic information (ExtendedStatus # Off) when the "server-status" handler is called. The default is Off. ExtendedStatus On //用於檢測apache的狀態信息. # User/Group: The name (or #number) of the user/group to run httpd as. # . On SCO (ODT 3) use "User nouser" and "Group nogroup". # . On HPUX you may not be able to use shared memory as nobody, and the # suggested workaround is to create a user www and use that user. # NOTE that some kernels refuse to setgid(Group) or semctl(IPC_SET) # when the value of (unsigned)Group is above 60000; # don't use Group #-1 on these systems! # User apache Group apache //設置apache工作時使用的用戶和組. 然後介紹主伺服器配置(### Section 2: 'Main' server configuration) # 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 root@localhost // 當伺服器發生問題的時候,apache會自動向這個郵箱發送相關郵件. # # If your host doesn't have a registered DNS name, enter its IP address here. # You will have to access it by its address anyway, and this will make # redirections work in a sensible way. # #ServerName www.example.com:80 //設定apache伺服器用於標識自身的名字和埠號.一般情況下,apache可以通過DNS伺服器獲得自身的名字,但伺服器沒有正式的 DNS名字時,需要我們設定.如果這個設置出錯,將導致伺服器不能正常啟動. # 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 "/var/www/html" //指定了主機中網頁文件的根目錄. ## <Directory /> Options FollowSymLinks AllowOverride None //設置apache根目錄的訪問許可權和訪問方式. </Directory> <Directory "/var/www/html"> Options Indexes FollowSymLinks AllowOverride None Order allow,deny //設置主伺服器網頁文件存放目錄的訪問許可權, Allow from all </Directory> <IfModule mod_userdir.c> UserDir disabled #UserDir public_html //表示設置用戶是否可以在自己的目錄下建立public_html目錄在存放自己的網頁文件,如果把userDir前面的#去掉,則表示用戶可以通過http://ip地址:埠/~用戶名 來訪問其中的內容. </IfModule> DirectoryIndex index.html index.html.var //設置預設首頁,默認是:index.html.設置以後,用戶通過“http://伺服器IP地址:埠/”訪問的就是"index.html". AccessFileName .htapacheace //設置apache目錄訪問許可權的控制文件,這裡我們設的是.htapacheace. <Files ~ "^.ht"> Order allow,deny Deny from all //防止用戶看到以.ht開頭的文件,保護.htaccess.htpasswd的內容.防止他人盜取相關用戶名和密碼. Satisfy All </Files> # TypesConfig describes where the mime.types file (or equivalent) is # to be found. TypesConfig /etc/mime.types //指定存放MIME文件類型的文件,用戶也可以編輯該文件. DefaultType text/plain //如果apache遇到不認識的文件類型的時候,自動將該文件當成文本文件 HostnameLookups Off //如果設置On,則每次都會向DNS伺服器要求解析該IP,這樣會花費額外的伺服器資源,並且降低伺服器的相應速度,一般設置為Off. ErrorLog logs/error_log //如果伺服器發生錯誤,所有的日誌文件都會存到log s/error_log 下. CustomLog logs/access_log combined //設置存取文件記錄採用combined模式. ServerSignature On // 當設置為On時,出錯的時候伺服器所產生的網頁會顯示Apache 的版本號、主機、連接埠等信息;如果設置為E-Mail,則會有“mailto:”的超鏈接 Alias /icons/ "/var/www/icons/" <Directory "/var/www/icons"> Options Indexes MultiViews FollowSymLinks AllowOverride None Order allow,deny //定義一個圖標虛擬目錄,並設置訪問許可權. Allow from all </Directory> ScriptAlias /cgi-bin/ "/var/www/cgi-bin/" <Directory "/var/www/cgi-bin"> AllowOverride None Options None Order allow,deny //設置腳本的文件目錄. Allow from all </Directory> IndexOptions FancyIndexing VersionSort NameWidth=* HTMLTable Charset=UTF-8 //採用更好看的帶有格式的文件列表方式 ,字元編碼為utf-8 AddIconByEncoding (CMP,/icons/compressed.gif) x-compress x-gzip AddIconByType (TXT,/icons/text.gif) text/* AddIconByType (IMG,/icons/image2.gif) image/* AddIconByType (SND,/icons/sound2.gif) audio/* AddIconByType (VID,/icons/movie.gif) video/* ............................ //文件列表各種文件類型對應的圖標顯示. DefaultIcon /icons/unknown.gif ReadmeName README.html HeaderName HEADER.html //顯示文件清單時,README.html的內容就會顯示在頁面的最下端,HEADER.html的內容就會顯示在頁面的最上端. IndexIgnore .??* *~ *# HEADER* README* RCS CVS *,v *,t //忽略這些類型的文件. # DefaultLanguage nl //設置頁面的默認語言,這一行通常是被註釋掉的. AddLanguage ca .ca AddLanguage cs .cz .cs AddLanguage da .dk .......... AddLanguage zh-CN .zh-cn //設置頁面語言 AddLanguage zh-TW .zh-tw LanguagePriority en ca cs da de el eo es et fr he hr it ja ko ltz nl nn no pl pt pt-BR ru sv zh-CN zh-TW //設置頁面語言的優先順序. AddDefaultCharset UTF-8 //設置默認的字元編碼格式. AddType application/x-compress .Z AddType application/x-gzip .gz .tgz //增加MIME的類型. AddType text/html .shtml AddOutputFilter INCLUDES .shtml //使用動態頁面 #ErrorDocument 500 "The server made a boo boo." #ErrorDocument 404 /missing.html #ErrorDocument 404 "/cgi-bin/missing_handler.pl" #ErrorDocument 402 http://www.example.com/subscription_info.html //設置各種錯誤類型的顯示方式. BrowserMatch "Mozilla/2" nokeepalive //如過瀏覽器符合這鐘類型,則不提供keepalive的支持. BrowserMatch "MSIE 4.0b2;" nokeepalive downgrade-1.0 force-response-1.0 BrowserMatch "RealPlayer 4.0" force-response-1.0 BrowserMatch "Java/1.0" force-response-1.0 BrowserMatch "JDK/1.0" force-response-1.0 //如果瀏覽器符合這四種方式,則採用“HTTP/1.0”回應. 是虛擬主機的配置(Section 3: Virtual Hosts) <VirtualHost *:80> ServerAdmin webmaster@dummy-host.example.com //配置虛擬主機管理員的電子郵件地址 DocumentRoot /www/docs/dummy-host.example.com //設置虛擬主機網頁存放位置 ServerName dummy-host.example.com //設置虛擬主機的名稱 ErrorLog logs/dummy-host.example.com-error_log //設置錯誤日誌的存放位置 CustomLog logs/dummy-host.example.com-access_log common //

CustomLog指令用來對伺服器的請求進行日誌記錄.可以使用環境變數根據請求的特徵來自由地組織日誌. </VirtualHost> 關於apache的更高級的配置,下面的blog將進行詳解.

本文出自 「lovecode」 博客,請務必保留此出處http://daaoao.blog.51cto.com/2329117/554176


[火星人 ] redhat enterprise linux 下 apache 服務的安裝與配置已經有908次圍觀

http://coctec.com/docs/linux/show-post-48738.html