apache httpd安裝 配置

raysuen發表於2017-01-06
安裝包
yum -y install httpd

命令
/usr/sbin/httpd
     httpd: root:root   主導程式(master process)
     httpd: apche:ache  工作程式(work process)

服務
/etc/init.d/httpd

埠:
     80 tcp
     443 ssl

工作的根目錄(相當於程式安裝目錄)
/etc/httpd
     /etc/httpd/conf  配置檔案目錄
          /etc/httpd/conf/httpd.conf  主配置檔案
          /etc/httpd/conf.d/*.conf 這些檔案都為主配置檔案的一部分,在主配置檔案中用include包含進去
     /etc/httpd/modules  模組目錄
     /etc/httpd/logs-->/var/log/httpd 日誌目錄
               日誌檔案有兩類:訪問日誌access_log,錯誤日誌:err_log
     /var/www/
               html  靜態頁面目錄
               cgi-bin

歡迎頁面:
/etc/httpd/conf.d/welcome.conf
     不顯示歡迎頁面
          [root@LinuxTest named]# mv /etc/httpd/conf.d/welcome.conf /etc/httpd/conf.d/welcome.conf.bak
          [root@LinuxTest named]# /etc/init.d/httpd restart
          Stopping httpd:                                            [  OK  ]
          Starting httpd:                                            [  OK  ]


建立測試頁面
echo -e "<html>
          <title>hello world</title>
          <h1>hello world</h1>
          welcome to our website
</html>" >> /var/www/html/index.html

/etc/httpd/conf/httpd.conf 詳解
主要分3個大部分,第二部分和第三部分不能同時生效
[root@LinuxTest named]# grep "Section" /etc/httpd/conf/httpd.conf
### Section 1: Global Environment
### Section 2: 'Main' server configuration
### Section 3: Virtual Hosts

Section 1:
ServerRoot "/etc/httpd" 伺服器的工作目錄,不要輕易改動
Timeout 60   tcp連線未成功建立連線的等待超時時間
KeepAlive Off  是否使用長連線
MaxKeepAliveRequests 100  每個長連線的最大請求數,0表示無限制
KeepAliveTimeout 15   長連線的斷開時長,單位秒
MPM Multi Path Modules
     prefork  一個請求用一個程式響應
          # StartServers: number of server processes to start  啟動服務是的程式數
          # MinSpareServers: minimum number of server processes which are kept spare 最少空閒程式數
          # MaxSpareServers: maximum number of server processes which are kept spare 最大空閒程式數
          # ServerLimit: maximum value for MaxClients for the lifetime of the server 指定maxclients的上線值
          # MaxClients: maximum number of server processes allowed to start          最多允許多少客戶端同時連線
          # MaxRequestsPerChild: maximum number of requests a server process serves  一個程式最多相應多少次請求
     worker      一個請求用一個執行緒響應。啟動多個程式,每個程式生成多個執行緒
          # StartServers: initial number of server processes to start      啟動服務的程式數
          # MaxClients: maximum number of simultaneous client connections  最大客戶端連線數
          # MinSpareThreads: minimum number of worker threads which are kept spare     最小空閒執行緒
          # MaxSpareThreads: maximum number of worker threads which are kept spare           最大空閒執行緒
          # ThreadsPerChild: constant number of worker threads in each server process  一個程式生成多少執行緒
          # MaxRequestsPerChild: maximum number of requests a server process serves    每個程式相應多少請求,0不作限定
     event    一個程式處理多個請求

     httpd -l 列出當前httpd指定的MPM模型
     修改HTTP的啟動預設MPM模型
          vi /etc/sysconfig/httpd 修改httpd的配置檔案
               HTTPD=/usr/sbin/httpd.worker
Listen 80 服務監聽的埠。IP可以省略,不寫IP表示監聽所有地址。Listen可以多個

Section 2:
ServerAdmin root@localhost  指定管理員email地址,每個站點都需要指定一個
ServerName 伺服器的名字,反解析IP到FQDN。注意:在虛擬主機,尤其是基於主機名的虛擬主機當中是必須的
DocumentRoot "/var/www/html"    指定文件根目錄
<Directory "/var/www/html">   定義根目錄的訪問許可權等
     Options Indexes FollowSymLinks  可選項:
                                                                                          None  不支援任何選項
                                                                                          Indexes(列出目錄內的資訊,生產中強烈不建議使用,除非是下載站)
                                                                                          Includes 不安全的,允許伺服器端包含(SSI)
                                                                                          FollowSymLinks 跟隨符號連結,允許訪問符號連結指向的檔案,強烈不建議使用
                                                                                          SymLinksifOwnerMatch 允許訪問符號連結執行的檔案,不建議使用
                                                                                          ExecCGI 允許執行CGI指令碼
                                                                                          MultiViews 多功能檢視(內容協商機制),除非是支援多語言,否則不建議使用
                                                                                          all 支援所有選項     
     AllowOverride None        允許覆蓋,覆蓋下面的2選項.可選項:All,None,AuthConfig(基於賬號認證)
                    htpasswd 建立密碼檔案(圖片2)
                         -c 建立密碼檔案
                         -m md5方式加密
                              htpasswd -c -m /etc/httpd/conf/htpasswd hadoop
                              htpasswd -m /etc/httpd/conf/htpasswd hadoop
     Order allow,deny    order 用於定義基於主機的訪問功能。(IP ,網路地址或主機定義訪問控制機制),allow和deny按照先後順序,順序很關鍵
     Allow from all      
          或deny from all,allow from 192.168.56.0/24(允許56網段訪問),也可以指定IP
</Directory>
DirectoryIndex index.html index.html.var  指定預設訪問頁面
HostnameLookups Off       在日誌中是否把IP反解析成主機名,不建議使用
ErrorLog logs/error_log   錯誤日誌
LogLevel warn             日誌級別。include: debug, info, notice, warn, error, crit,alert, emerg.
LogFormat                 指定日誌格式

Section 3:(圖片3)


配置檔案語法檢查:httpd -t 檢查配置檔案語法

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28572479/viewspace-2131983/,如需轉載,請註明出處,否則將追究法律責任。

相關文章