http.conf配置檔案說明
httpd:高度模組化
core + modules
DSO:Dynamic Shared Object
MPM:Multi-Processing Module 多執行緒處理模組,不是指一個模組
prefork:多個子程式,一個子程式一個請求
worker:多個子程式,一個程式多個執行緒,一個執行緒一個請求
event:(2.4支援)
httpd的功能特性
路徑別名:alias
使用者認證:authentication
虛擬主機:virtual host
反向代理:
負責均衡:
使用者站點:
CGI:common Gateway interface
Apache安裝目錄結構
/etc/httpd/conf/ :配置檔案目錄
/etc/httpd/conf.d/ :配置檔案子目錄
/etc/httpd/logs :日誌目錄,軟連線到/var/log/httpd
/var/www/html :文件根目錄
/var/www/cgi-bin/ :CGI目錄
/etc/httpd/conf/magic :記錄對多媒體型別(MIME)的支援
httpd.conf檔案的格式
全域性配置:
主機配置:用於僅提供一個站點時
虛擬配置:用於提供多個站點時
注:主機配置和虛擬配置不能同時啟用,配置檔案修改完畢,要做配置檔案語法測試,httpd -t
區分全域性配置、主機配置、虛擬主機配置
grep "Section" /etc/httpd/conf/httpd.conf
vim /etc/sysconfig/httpd ---> HTTPD=/usr/sbin/httpd.worker 使用不同的MPM模組
global區域
ServerRoot "/etc/httpd" :定義工作目錄
KeepAlive Off :是否啟用保持連線
main區域
DocumentRoot "/var/www/html" :訪問網頁的根目錄
DirectoryIndex index.html :在瀏覽器中不指定uri路徑,預設呈現的網頁檔名字
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
CustomLog logs/access_log combined :訪問日誌路徑
Alias /images/ "/data/imgs/" :/images為瀏覽器要訪問的路徑,/data/imgs/伺服器真實的目錄
AddDefaultCharset UTF-8
<Directory /> :用於訪問控制,支援正規表示式
Options
FollowSymLinks:允許軟連線當做網頁檔案
indexes:缺少指定的預設頁面時,允許將目錄中的所有檔案以列表的形式返回給使用者
none:所有先選都不生效
ExecCGI:允許使用mod_cgi模組執行CGI指令碼;
includes:允許使用mod_include模組
MultiViews:允許使用mod_negotiation實現內容協商
AllowOverride None/auth :底下訪問控制是否被禁用,和是否開啟認證
</Directory>
使用者目錄
如果希望讓每個使用者都可以建立個人站點:~Username/
<IfModule mod_userdir.c>
UserDir disabled/public_html_dir
</IfModule>
setfacl -m u:apache:rx /home/hadoop
DSO模組載入方式
loadModule module_name /path/to/module
如:loadModule php5_module /usr/lib64/httpd/modules/php5.so
如果使用相對路徑,則對於ServerRoot所定義的位置而言的;
httpd -l:列出所有非DSO(shared)的模組
httpd -M: 列出所有模組
配置日誌功能
/var/log/httpd/
access.log:訪問日誌 ;其記錄內容需要自定義 CustomLog
error.log:錯誤日誌
指令碼路徑別名
ScriptAlias /url "/path/to/somewhere"
CGI:common Gateway Interface 協議
CGI需要呼叫SUID,SGID來實現,很不安全
指令碼一:(Content-Type下必須有空行)
#!/bin/sh
cat << EOF
Content-Type:text/html
<pre>
The hostname is:`hostname`.
The time is:`date`.
</pre>
EOF
指令碼二:
#!/bin/sh
echo "Content-Type:text/html"
echo -e "\n"
echo "<p1>The hostname is:$(hostname).</p1>"
echo "<p2>The time is:$(date).</p2>"
基於使用者的控制
虛擬使用者
基於檔案:/etc/httpd/conf/.htpasswd
sql資料庫:
ldap:輕量級目錄訪問協議
模組以auth開頭的代表認證型別:
模組以authn開頭的代表認證提供者:
模組以authz開頭的代表授權機制:
<Directory "/www/htdocs/fin">
Options None
AllowOverride AuthConfig :啟用認證
AuthType Basic :認證型別
AuthName "ti shi xin xi" :提示資訊
AuthBasicProvider file
AuthUserFile /etc/httpd/conf/.htpasswd :認證檔案
Require valid-user :過濾使用者
</Directory>
htpasswd -c -m /etc/httpd/conf/.htpasswd tom
htpasswd -m /etc/httpd/conf/.htpasswd jerry
虛擬主機
關閉中心主機,即註釋Section2的 #DocumentRoot
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin
DocumentRoot /www/htdocs
ServerName /> ErrorLog logs/a.com.error_log
CustomLog logs/a.com.access_log common
</VirtualHost>
伺服器status頁面
內生的status資訊,且此資訊可以透過web預以顯示
配置檔案系統路徑訪問屬性
<Directory[Match] "">=<Directory [~]"">
<File[Match] "">=<File [~]"">
基於URL訪問屬性
<Location[Match] "">=<Location [~]"">
注:Match啟用正則
如果某要配置其屬性的URL能對映到某具體的檔案系統路徑時,建議使用<Directory>
啟用status需要的模組
grep status_mod /etc/httpd/conf/httpd.conf
httpd -M | grep status
vim /etc/httpd/conf/httpd.conf
<Location /status>
SetHandler server-status
Order deny,allow
allow from all
</Location>
使用mod_deflate模組壓縮頁面最佳化傳輸速度
httpd -M | grep deflate
vim /etc/httpd/conf.d/deflate.conf
SetOutputFilter DEFLATE
<IfModule mod_deflate.c>
# Restrict compression to these MIME types
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/css
# Level of compression (Highest 9 - Lowest 1)預設為6
DeflateCompressionLevel 9
# Netscape 4.x has some problems.
BrowserMatch ^Mozilla/4 gzip-only-text/html
# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip
# MSIE masquerades as Netscape, but it is fine
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
</IfModule>
core + modules
DSO:Dynamic Shared Object
MPM:Multi-Processing Module 多執行緒處理模組,不是指一個模組
prefork:多個子程式,一個子程式一個請求
worker:多個子程式,一個程式多個執行緒,一個執行緒一個請求
event:(2.4支援)
httpd的功能特性
路徑別名:alias
使用者認證:authentication
虛擬主機:virtual host
反向代理:
負責均衡:
使用者站點:
CGI:common Gateway interface
Apache安裝目錄結構
/etc/httpd/conf/ :配置檔案目錄
/etc/httpd/conf.d/ :配置檔案子目錄
/etc/httpd/logs :日誌目錄,軟連線到/var/log/httpd
/var/www/html :文件根目錄
/var/www/cgi-bin/ :CGI目錄
/etc/httpd/conf/magic :記錄對多媒體型別(MIME)的支援
httpd.conf檔案的格式
全域性配置:
主機配置:用於僅提供一個站點時
虛擬配置:用於提供多個站點時
注:主機配置和虛擬配置不能同時啟用,配置檔案修改完畢,要做配置檔案語法測試,httpd -t
區分全域性配置、主機配置、虛擬主機配置
grep "Section" /etc/httpd/conf/httpd.conf
vim /etc/sysconfig/httpd ---> HTTPD=/usr/sbin/httpd.worker 使用不同的MPM模組
global區域
ServerRoot "/etc/httpd" :定義工作目錄
KeepAlive Off :是否啟用保持連線
main區域
DocumentRoot "/var/www/html" :訪問網頁的根目錄
DirectoryIndex index.html :在瀏覽器中不指定uri路徑,預設呈現的網頁檔名字
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
CustomLog logs/access_log combined :訪問日誌路徑
Alias /images/ "/data/imgs/" :/images為瀏覽器要訪問的路徑,/data/imgs/伺服器真實的目錄
AddDefaultCharset UTF-8
<Directory /> :用於訪問控制,支援正規表示式
Options
FollowSymLinks:允許軟連線當做網頁檔案
indexes:缺少指定的預設頁面時,允許將目錄中的所有檔案以列表的形式返回給使用者
none:所有先選都不生效
ExecCGI:允許使用mod_cgi模組執行CGI指令碼;
includes:允許使用mod_include模組
MultiViews:允許使用mod_negotiation實現內容協商
AllowOverride None/auth :底下訪問控制是否被禁用,和是否開啟認證
</Directory>
使用者目錄
如果希望讓每個使用者都可以建立個人站點:~Username/
<IfModule mod_userdir.c>
UserDir disabled/public_html_dir
</IfModule>
setfacl -m u:apache:rx /home/hadoop
DSO模組載入方式
loadModule module_name /path/to/module
如:loadModule php5_module /usr/lib64/httpd/modules/php5.so
如果使用相對路徑,則對於ServerRoot所定義的位置而言的;
httpd -l:列出所有非DSO(shared)的模組
httpd -M: 列出所有模組
配置日誌功能
/var/log/httpd/
access.log:訪問日誌 ;其記錄內容需要自定義 CustomLog
error.log:錯誤日誌
指令碼路徑別名
ScriptAlias /url "/path/to/somewhere"
CGI:common Gateway Interface 協議
CGI需要呼叫SUID,SGID來實現,很不安全
指令碼一:(Content-Type下必須有空行)
#!/bin/sh
cat << EOF
Content-Type:text/html
<pre>
The hostname is:`hostname`.
The time is:`date`.
</pre>
EOF
指令碼二:
#!/bin/sh
echo "Content-Type:text/html"
echo -e "\n"
echo "<p1>The hostname is:$(hostname).</p1>"
echo "<p2>The time is:$(date).</p2>"
基於使用者的控制
虛擬使用者
基於檔案:/etc/httpd/conf/.htpasswd
sql資料庫:
ldap:輕量級目錄訪問協議
模組以auth開頭的代表認證型別:
模組以authn開頭的代表認證提供者:
模組以authz開頭的代表授權機制:
<Directory "/www/htdocs/fin">
Options None
AllowOverride AuthConfig :啟用認證
AuthType Basic :認證型別
AuthName "ti shi xin xi" :提示資訊
AuthBasicProvider file
AuthUserFile /etc/httpd/conf/.htpasswd :認證檔案
Require valid-user :過濾使用者
</Directory>
htpasswd -c -m /etc/httpd/conf/.htpasswd tom
htpasswd -m /etc/httpd/conf/.htpasswd jerry
虛擬主機
關閉中心主機,即註釋Section2的 #DocumentRoot
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin
DocumentRoot /www/htdocs
ServerName /> ErrorLog logs/a.com.error_log
CustomLog logs/a.com.access_log common
</VirtualHost>
伺服器status頁面
內生的status資訊,且此資訊可以透過web預以顯示
配置檔案系統路徑訪問屬性
<Directory[Match] "">=<Directory [~]"">
<File[Match] "">=<File [~]"">
基於URL訪問屬性
<Location[Match] "">=<Location [~]"">
注:Match啟用正則
如果某要配置其屬性的URL能對映到某具體的檔案系統路徑時,建議使用<Directory>
啟用status需要的模組
grep status_mod /etc/httpd/conf/httpd.conf
httpd -M | grep status
vim /etc/httpd/conf/httpd.conf
<Location /status>
SetHandler server-status
Order deny,allow
allow from all
</Location>
使用mod_deflate模組壓縮頁面最佳化傳輸速度
httpd -M | grep deflate
vim /etc/httpd/conf.d/deflate.conf
SetOutputFilter DEFLATE
<IfModule mod_deflate.c>
# Restrict compression to these MIME types
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/css
# Level of compression (Highest 9 - Lowest 1)預設為6
DeflateCompressionLevel 9
# Netscape 4.x has some problems.
BrowserMatch ^Mozilla/4 gzip-only-text/html
# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip
# MSIE masquerades as Netscape, but it is fine
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
</IfModule>
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29620572/viewspace-1773071/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Nginx的配置檔案說明Nginx
- Docker 的配置檔案說明Docker
- Apache 配置檔案說明(轉)Apache
- Nginx配置檔案詳細說明Nginx
- saltstack/saltmaster配置檔案說明(二)AST
- Redis配置檔案引數說明Redis
- linux /etc/fstab檔案配置說明Linux
- web.xml檔案配置的說明WebXML
- CentOS8中systemd配置檔案說明CentOS
- Infer - 檔案說明
- 檔案-spfile說明
- DB2 Content Manager 配置檔案說明DB2
- [轉]Nginx 配置檔案nginx.conf的完整配置說明Nginx
- fepk檔案格式說明
- Centos7 中 Systemd 的Unit檔案配置說明CentOS
- Centos系統中 Systemd 的Unit檔案配置說明CentOS
- redis配置檔案redis.conf詳細說明Redis
- log4j配置檔案基本含義說明
- hosts檔案格式說明,為什麼還有域名配置
- MySQL配置檔案my.ini引數註釋說明MySql
- LINUX常用檔案說明Linux
- android混淆檔案說明Android
- 檔案-init.ora說明
- MySQL 日誌檔案 說明MySql
- Linux下玩轉nginx系列(二)——nginx配置檔案說明LinuxNginx
- Nginx的nginx.conf配置檔案中文註釋說明Nginx
- linux日誌檔案說明Linux
- oracle控制檔案轉儲說明Oracle
- Linux的基本檔案說明Linux
- Kafka配置說明Kafka
- FTP配置說明FTP
- 簡單說說webpack的配置檔案Web
- django的初始化檔案說明Django
- C/C++標頭檔案說明C++
- Linux下玩轉nginx系列(三)---nginx日誌配置檔案說明LinuxNginx
- Spring配置說明Spring
- C++檔案說明及使用方法C++
- oracle 資料檔案(Datafile ) 大小 限制 說明Oracle