若是安裝centos,系統自己已經安裝了apache,名字爲httpd這個服務就是對應的apachehtml
service httpd start service httpd stop service httpd restart
下面介紹一下apache的幾個重要的配置文件apache
1 httpd.confcentos
這個文件在/etc/httpd/conf目錄下,文件大體分爲三個部分:服務器
主服務器部分ide
這個部分主要是使用一些參數定義服務器的功能等等。spa
### Section 1: Global Environment ServerTokens OS ... ServerRoot "/etc/httpd" ---------定義與服務器所在的目錄,這個目錄在安裝時由-prefix=ServerRoot 來選定 ... PidFile run/httpd.pid ... Timeout 60 ... KeepAlive Off ... MaxKeepAliveRequests 100 ... KeepAliveTimeout 15 ...
ServerAdmin root@localhost-----------定義當服務器出現錯誤後提示給客戶端的管理員郵件地址
#ServerName www.example.com:80----------定義apache默認的主機名字,但默認備註釋掉
DocumentRoot "/var/www/html"----------指令用於指定apache所提供頁面服務的根目錄
Alias /error/ "/var/www/error/"-----------實現映射目錄功能,映射爲一個普通目錄
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"----------實現映射,與Alias不一樣的是它將映射的目錄識別爲CGI腳本目錄並將此目錄中的全部文件都做爲CGI腳原本對待
User apache Group apache--------定義運行apache服務器的帳號和工做組,用來定義用戶請求時所建立的子進程的帳號與工做組
#Listen 12.34.56.78:80--------定義監聽端口號,默認是80 Listen 80
# Example:---------------------------------------------------用於加載模塊的目標文件 # LoadModule foo_module modules/mod_foo.so # LoadModule auth_basic_module modules/mod_auth_basic.so LoadModule auth_digest_module modules/mod_auth_digest.so LoadModule authn_file_module modules/mod_authn_file.so LoadModule authn_alias_module modules/mod_authn_alias.so LoadModule authn_anon_module modules/mod_authn_anon.so LoadModule authn_dbm_module modules/mod_authn_dbm.so LoadModule authn_default_module modules/mod_authn_default.so LoadModule authz_host_module modules/mod_authz_host.so LoadModule authz_user_module modules/mod_authz_user.so LoadModule authz_owner_module modules/mod_authz_owner.so LoadModule authz_groupfile_module modules/mod_authz_groupfile.so LoadModule authz_dbm_module modules/mod_authz_dbm.so LoadModule authz_default_module modules/mod_authz_default.so LoadModule ldap_module modules/mod_ldap.so
# Some examples:---------------------------當錯誤時,apache定義一個http相應代碼,並根據相應代碼顯示相應網頁 #ErrorDocument 500 "The server made a boo boo." #ErrorDocument 404 /missing.html #ErrorDocument 404 "/cgi-bin/missing_handler.pl" #ErrorDocument 402 http://www.example.com/subscription_info.html
<Directory "/var/www/error"> AllowOverride None Options IncludesNoExec----------------決定在那些目錄中使用那些服務器的特性 AddOutputFilter Includes html AddHandler type-map var Order allow,deny Allow from all LanguagePriority en es de fr ForceLanguagePriority Prefer Fallback </Directory>
容器環境部分rest
<IfModule>做用於模塊,它會首先判斷是否載入,而後決定是否進行處理。code
<IfModule mod_dav_fs.c> # Location of the WebDAV lock database. DAVLockDB /var/lib/dav/lockdb </IfModule>
<IfDefine>與上面的<IfModule>相似,只有對應的條件知足時,纔會執行。server
<Directory>模塊做用是讓它所封裝的指令在指定的目錄以它的子目錄中中起做用,這個目錄必須是一個完整的路徑。htm
<Directory "/var/www/error"> AllowOverride None Options IncludesNoExec AddOutputFilter Includes html AddHandler type-map var Order allow,deny Allow from all LanguagePriority en es de fr ForceLanguagePriority Prefer Fallback </Directory>
<Files>這個容器與<Directory>容器做用於目錄相對應,<Files>容器只做用於文件
<Files ~ "^\.ht"> Order allow,deny Deny from all Satisfy All </Files>
<Location>對到來的URL進行匹配
#<Location /server-status> # SetHandler server-status # Order deny,allow # Deny from all # Allow from .example.com #</Location>
服務器擴展部分
這個部分主要就是用Inlcude來加載配置文件
Include conf.d/*.conf
在/etc/httpd/conf.d目錄中:
[root@localhost httpd]# cd conf.d/ [root@localhost conf.d]# ls mod_dnssd.conf README welcome.conf [root@localhost conf.d]#