Linux的httpd服務搭建

在服務搭建前,還要了解一下httpd的日誌。html

日誌有助有工做人員,查看服務器出錯情況,更能統計數據分析網頁運行狀況。web

PV和UV兩大分析

PV  Page View 頁面訪問量
UV  User View 用戶訪問量

1)指定錯誤日誌的名稱及級別vim

錯誤日誌的路徑:/var/log/httpd/error_log瀏覽器

錯誤級別: debug, info, notice, warn, error, crit服務器

訪問日誌: /var/log/httpd/access_logide

[root@wei httpd]# head -n 1 /var/log/httpd/access_log


(2)定義訪問日誌的格式網站

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

192.168.196.1 - - [07/Mar/2019:05:33:39 +0800] "GET / HTTP/1.1" 200 1766 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36"

       
       %h 遠端主機
       %l 遠端登陸名(由identd而來,若是支持的話),除非IdentityCheck設爲"On",不然將獲得一個"-"。
       %u 遠程用戶名(根據驗證信息而來;若是返回status(%s)爲401,多是假的)
       %t 時間,用普通日誌時間格式(標準英語格式)
       %r 請求的第一行
       %>s:HTTP狀態碼
       %b 以CLF格式顯示的除HTTP頭之外傳送的字節數,也就是當沒有字節傳送時顯示’-'而不是0。
       %{Referer}i:記錄超連接地址
       %{User-Agent}i:記錄客戶端的瀏覽器類型
debug


(3)指定訪問日誌的名稱及格式rest

 CustomLog "logs/access_log" combined

 

虛擬主機 VirtualHost

    做用:在一臺物理服務器上運行多個網站
    
    類型:
         基於域名的虛擬主機(經常使用)
         基於IP地址的虛擬主機
         基於端口的虛擬主機
         
配置虛擬主機

<VirtualHost 10.1.2.3:80>
  ServerAdmin webmaster@host.example.com
  DocumentRoot /www/docs/host.example.com
  ServerName host.example.com
  ErrorLog logs/host.example.com-error_log
  TransferLog logs/host.example.com-access_log
</VirtualHost>


示例:基於主機名的虛擬主機

  www.a.org    網頁目錄:/var/www/html/a.org   日誌:/var/log/httpd/a.org
 

 www.a.org  

(1)準備目錄

[root@wei ~]# mkdir /var/www/html/a.org
[root@wei ~]# vim /var/www/html/a.org/index.html
[root@wei ~]# mkdir /var/log/httpd/a.org

(2)編寫配置文件

[root@wei ~]# vim /etc/httpd/conf.d/a.org.conf
<VirtualHost 192.168.196.132:80>
  DocumentRoot /var/www/html/a.org
  ServerName www.a.org
  ErrorLog /var/log/httpd/a.org/error_log
  CustomLog /var/log/httpd/a.org/access_log combined

</VirtualHost>


(3)檢測配置文件語法

[root@wei ~]# httpd -t

(4)重啓服務

[root@wei ~]# systemctl restart httpd
相關文章
相關標籤/搜索