Httpd的簡單介紹html
web服務:nginx
其監聽的端口http: 80/TCPweb
https: 443/TCPapache
http協議響應碼:安全
1××:信息服務器
2××:常響應信息ide
3××:重定向ui
4××:客戶端錯誤加密
5××:服務器端錯誤spa
web服務器軟件:
apache
iis
lighttpd
nginx 對於靜態請求
CGI:common gateway interface
同一個服務器上的進程,每次啓動都要經過服務器的調用
module:當啓用應用進程的時候是跑在web進程的裏邊
httpd -M 查看安裝了哪些模塊
NPM:Multipath 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 webmaster@magedu.com
alias
scriptalias
</VirtualHost>
要是開啓虛擬主機要把#DocumentRoot "/var/www/html"這一項禁用了,
要是基於主機頭就要把 NameVirtualHost *:80 這一項開啓