Apache主配置文件內容詳解php
(一)基本配置html
ServerRoot"/usr/local/apache2" //服務目錄apache
Listen 80 //監聽的ip地址、端口號服務器
#LoadModule...... //啓動時加載的模塊網絡
LoadModule deflate_modulemodules/mod_deflate.soapp
LoadModule expires_modulemodules/mod_expires.sodom
LoadModule rewrite_modulemodules/mod_rewrite.soide
<IfModule !mpm_netware_module>網站
<IfModule !mpm_winnt_module>ui
User daemon //運行服務的用戶身份
Group daemon //運行服務的組身份
</IfModule>
</IfModule>
ServerAdmin you@example.com
ServerName localhost:80 //網站服務器域名
DocumentRoot"/usr/local/apache2/htdocs" //網頁文檔的根目錄
#配置虛擬主機
NameVirtualHost10.1.4.90
<VirtualHost 10.1.4.90:80>
DocumentRoot/home/httpd/html1
ServerNamewww.ok1.com
ErrorLog /usr/local/apache/logs/error1_log
CustomLog /usr/local/apache/logs/access1_logcombined
</VirtualHost>
#下面是對根目錄的一個權限設置
<Directory />
Options FollowSymLinks
Order deny,allow //對頁面的訪問控制順序,後面的一項是默認選項,故此配置默認是allow
Deny from all
</Directory>
<Directory"/usr/local/apache2/htdocs">
AllowOverride None
Order allow,deny
Allow from all //表示容許全部的用戶,經過和上一項結合能夠控制對網站的訪問控制
</Directory>
<IfModule dir_module>
DirectoryIndex index.html //默認的索引頁文件,還能夠添加index.php、index.htm等
</IfModule>
<FilesMatch "^\.ht">
Order allow,deny
Deny from all
Satisfy All
</FilesMatch>
ErrorLog "logs/error_log" //錯誤日誌文件
LogLevel warn //記錄日誌的級別,默認爲warn
<IfModule log_config_module>
LogFormat "%h %l %u %t \"%r\" %>s %b\"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
<IfModule logio_module>
LogFormat "%h %l %u %t \"%r\" %>s %b\"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
</IfModule>
CustomLog "logs/access_log" common //訪問日誌文件
</IfModule>
<IfModule alias_module>
ScriptAlias /cgi-bin/ "/usr/local/apache2/cgi-bin/"
</IfModule>
<IfModule cgid_module>
</IfModule>
<Directory "/usr/local/apache2/cgi-bin">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>
DefaultType text/plain
<IfModule mime_module>
TypesConfig conf/mime.types
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
</IfModule>
<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>
(二)虛擬主機
(注:以建立兩個虛擬主機wgmml和rsysxx爲例。)
1、基於域名的虛擬主機:使用不一樣的域名
NameVirtualHost10.1.4.90
<VirtualHost 10.1.4.90>
DocumentRoot/user/local/apache2/htdocs/wgmml
ServerNamewww.wgmml.com
ErrorLog /usr/local/apache/logs/www.wgmml.com .error1_log
CustomLog /usr/local/apache/logs/www.wgmml.com.access1_logcommon
</VirtualHost>
NameVirtualHost10.1.4.90
<VirtualHost 10.1.4.90>
DocumentRoot/user/local/apache2/htdocs/reysxx
ServerNamewww.rsysxx.com
ErrorLog /usr/local/apache/logs/www.rsysxx.com .error1_log
CustomLog /usr/local/apache/logs/www.rsysxx.com.access1_logcommon
</VirtualHost>
2、基於ip的虛擬主機:使用不一樣的ip
<VirtualHost 10.1.4.90>
DocumentRoot/user/local/apache2/htdocs/wgmml
ServerNamewww.wgmml.com
ErrorLog /usr/local/apache/logs/www.wgmml.com .error1_log
CustomLog /usr/local/apache/logs/www.wgmml.com.access1_logcommon
</VirtualHost>
<VirtualHost 10.1.2.73>
DocumentRoot/user/local/apache2/htdocs/reysxx
ServerNamewww.rsysxx.com
ErrorLog /usr/local/apache/logs/www.rsysxx.com .error1_log
CustomLog /usr/local/apache/logs/www.rsysxx.com.access1_logcommon
</VirtualHost>
3、基於端口的虛擬主機:使用不一樣的端口
Listen10.1.2.73:80
Listen10.1.2.73:8080
<VirtualHost 10.1.2.73:80>
DocumentRoot/user/local/apache2/htdocs/wgmml
ServerNamewww.wgmml.com
ErrorLog /usr/local/apache/logs/www.wgmml.com .error1_log
CustomLog /usr/local/apache/logs/www.wgmml.com.access1_logcommon
</VirtualHost>
<VirtualHost 10.1.2.73:8080>
DocumentRoot/user/local/apache2/htdocs/reysxx
ServerNamewww.rsysxx.com
ErrorLog /usr/local/apache/logs/www.rsysxx.com .error1_log
CustomLog /usr/local/apache/logs/ www.rsysxx.com.access1_logcommon
</VirtualHost>
(三)其餘全局配置參數
LogLevel:記錄日誌的級別,默認爲warn
Timeout 300:網絡鏈接超時,默認爲300秒
KeepAlive:是否保持鏈接,可選On或Off
MaxKeepAliveRequests100:每次鏈接最多請求文件數,0表示無限次
KeepAliveTimeout15:保持鏈接狀態時的超時時間,超過期間自動斷開