Httpd服務的簡單介紹

Httpd的簡單介紹

web服務:

  其監聽的端口http: 80/TCP

              https: 443/TCP

 

http協議響應碼:

  1××:信息

  2××:常響應信息

  3××:重定向

  4××:客戶端錯誤

  5××:服務器端錯誤

 

web服務器軟件:

  apache 

  iis

  lighttpd

  nginx 對於靜態請求

 

CGIcommon gateway interface

  同一個服務器上的進程,每次啓動都要通過服務器的調用

  module:當啓用應用進程的時候是跑在web進程的裏邊

 

httpd -M 查看安裝了哪些模塊

  NPMMultipath Processing Module 多路(道)處理模塊

  prefork:每一個請求用一個進程來響應

           穩定性、安全性好

  worker:每一個請求用一個線程來響應(線程是進程的機制)

          輕量級創建/銷燬,資源消耗率低

  

  

主配置文件 /etc/httpd/conf/http.conf

裏面所包含的信息介紹:

   ServerTokens OS(顯示操作系統信息)

    它可以有以下幾種方式:

    ServerTokens Prod[uctOnly]

       Server sends (e.g.): Server: Apache

    ServerTokens Major

       Server sends (e.g.): Server: Apache/2

    ServerTokens Minor

       Server sends (e.g.): Server: Apache/2.0

    ServerTokens Min[imal]

       Server sends (e.g.): Server: Apache/2.0.41 

    ServerTokens OS

       Server sends (e.g.): Server: Apache/2.0.41 (Unix)

    ServerTokens Full (or not specified)

       Server sends (e.g.): Server: Apache/2.0.41 (Unix) PHP/4.2.2 MyMod/1.2 

  

  ServerRoot "/etc/httpd" 服務器起點的安裝路徑

  PidFile run/httpd.pid pid文件的路徑

  KeepAlive Off 是否開啓保持連接

  MaxKeepAliveRequests 100

  KeepAliveTimeout 15

  Timeout 120

  

  <IfModule prefork.c> 查看模塊是否存在

  StartServers       8   啓動是啓動幾個進程

  MinSpareServers    5  最少空閒進程數

  MaxSpareServers   20  最多空閒進程數

  ServerLimit      256   最大啓動的進程數

  MaxClients       256   最多多少個請求

  MaxRequestsPerChild  4000  一個進程最多響應多少個請求

  </IfModule>

  

  Listen 80 監聽的端口

  ExtendedStatus On 是否開啓擴展狀態

  DocumentRoot "/var/www/html" 網頁文件的存放位置

  Options Indexes FollowSymLinks  

     Indexes 允許索引,表示如果沒有主頁的則列出/var/www/html下的內容

     FollowSymLinks 跟蹤鏈接

     SymLinksifOwnerMatch 允許用戶跟蹤鏈接

 

  Order allow,deny  基於客戶端來源的ACL,放在後面的默認最先的規則

   deny from  後面可以跟IP地址 域名

  

  AllowOverride AuthConfig

  AuthName "feng" 認證名稱

  AuthType Basic 認證類型

  AuthUserFile /etc/httpd/conf/.htpasswd 用戶的認證文件位置

  AuthGroupFile /etc/httpd/conf/.htgroup 只有列在這個組中的用戶才能訪問的文件

   .htgroup文件中內容的格式是 組名:用戶 用戶

  Require user gentoo 指定允許誰訪問

  Require valid-user 允許在.htpasswd文件中有密碼的用戶訪問

  Require group developers

 

#service httpd configtest 檢查配置文件是否有語法錯誤

#httpd -t 檢查配置文件是否有語法錯誤

#htpasswd -c 創建密碼文件當文件不存在時才用

          -m 採用md5加密

          -D 刪除某個用戶

  

  UserDir public_html 讓用戶自己的家目錄可以使用網頁文件

    先在自己的家目錄裏創建目錄public_html,在目錄中編寫網頁文件,在我們訪問的時候輸入ip的後面加上/~用戶名即可

 

  DirectoryIndex 默認主頁面

  ErrorLog logs/error_log 錯誤日誌,全路徑是/etc/httpd/logs/error_log

  LogLevel warn  定義日誌級別 顯示的都是超過此級別的信息  

錯誤級別debug(調試級別), info(), notice(注意), warn(警告), error(錯誤), crit(藍色預警),alert(黃色預警), emerg(紅色警戒)

 

  日誌格式:   

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined

    LogFormat "%h %l %u %t \"%r\" %>s %b" common(自己定的名稱)

    LogFormat "%{Referer}i -> %U" referer

    LogFormat "%{User-agent}i" agent

%h 遠端主機的IP地址 %l 表示登錄名稱 %u 遠程用戶的用戶名 %t 訪問時間 

%r 請求信息首部的第一行 %s 狀態碼 %b 響應信息的大小 %{Referer}i 訪問當頁面是從哪跳過來的 %{User-Agent}i 用戶代理

  CustomLog logs/access_log combined(使用的哪種格式) 訪問日誌的格式

  Alias /icons/ "/var/www/icons/" 定義別名,可以讓不在/var/www/html目錄下的其他網頁也可以訪問

  

  啓用status 可以查看進程的詳細信息

  <Location /status>

    SetHandler server-status

    Order deny,allow

#    Deny from all

#    Allow from .example.com      

  </Location>

 

虛擬主機的建立:

     一個物理主機上只有一個httpd,但能運行N個站點

  虛擬主機的類型:

     基於IP

     基於端口

     基於主機頭FQDN

 

<VirtualHost 172.16.100.1:80>

DocumentRoot "/path/to/somewhere"

ServerName www.magedu.com

<Directory "/path/to/somewhere">

Options Indexes

AllowOverride none

Order allow,deny

Allow from 172.16

</Directory>

ErrorLog /var/log/httpd/www.magedu.com_error_log

CustomLog /var/log/httpd/www.magedu.com_access_log combined

ServerAdmin [email protected]

alias

scriptalias

</VirtualHost>

 

要是開啓虛擬主機要把#DocumentRoot "/var/www/html"這一項禁用了,

要是基於主機頭就要把  NameVirtualHost *:80 這一項開啓




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章