Apache 配置文件的含義

轉自:http://www.oschina.net/discuss/thread/176

/etc/apache/httpd.conf :

ServerRoot "/usr"
#因爲安裝到/usr下,所以ServerRoot是/usr。在以下配置中,以相對路徑寫的就是對於相對/usr
PidFile /var/run/httpd.pid
#httpd啓動時的pid存放位置,用於start/stop apache
Timeout 300
#連接超時時間
KeepAlive On
#允許持續連接,一個連接多個請求.
MaxKeepAliveRequests 200
#持續連接中最大連接數,推薦大一些獲得最佳性能
KeepAliveTimeout 15
#Client 在15秒內沒有下次請求則斷線
MinSpareServers      5
MaxSpareServers      10
httpd服務進程的數量,ps aux 可以看到
MaxClients         150
最大連接人數
Listen 80
#監聽端口
#ExtendedStatus On
#使用/server-status查詢服務器狀態時給予完全信息(ON)或基本信息(OFF) 默認爲OFF
User apache
Group apache
#httpd進程的user,group
ServerAdmin [email protected]
#admin的E-mail
ServerName 127.0.0.1
#服務器名稱,需要是合法的DNS NAME 或者設置成IP

DocumentRoot "/srv/www/htdocs"
#主頁存放目錄
UserDir public_html
#每個用戶的主頁目錄 (例如:/home/blue/public_html)
DirectoryIndex index.php index.html index.html.var
#當輸入http://localhost 就會在主頁根目錄下搜索以上幾個文件名做爲首頁顯示
HostnameLookups Off
#記錄log時,Client以主機名(On)或以IP(Off)記錄,以IP記錄更快些.
ErrorLog /var/log/apache/error_log
#錯誤日誌位置
LogLevel warn
#日誌記錄等級,由信息多->少記錄等級:debug, info, notice, warn, error, crit,alert,emerg
CustomLog /var/log/apache/access_log common
#訪問日誌位置
ServerTokens Prod
#當client訪問到不存在的網頁時提供信息的多少。少點好些 :)
#由多-->少 :Full | OS | Minor | Minimal | Major | Prod
LanguagePriority zh-CN en ca cs da de ..........
#語言優先級
ErrorDocument 404 /missing.html
#錯誤網頁處理,當出現404(找不到該頁)則會顯示/missing.html

目錄設定:
設定根目錄屬性:

    Options FollowSymLinks
    AllowOverride None

Options 屬性:
Indexes         當該目錄下沒有index.*時則以ftp-style列出該目錄下所有文件
Includes        Allow server-wide includes
FollowSymLinks 當該目錄下軟連接的文件/目錄鏈接到外部目錄時,仍然可以正常顯示。
MultiViews     由一個*.var管理同一網頁的多種語言版本,如apache默認主頁多種語言的index.html
ExecCGI         允許執行CGI程序
ALL             開啓除MultiViews之外的屬性
None            禁止所有屬性

AllowOverride 是否允許使用.htaccess覆蓋某些設定(All None FileInfo AuthConfig Limit)

設定/srv/www/htdocs/ 目錄(根目錄)屬性:


Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
    Allow from all


Order allow,deny : 控制訪問權限
Order deny,allow
deny from test.org 拒絕test.org訪問
deny from 192.168.0.100 拒絕192.168.0.100訪問
allow from 192.168.0.1 允許192.168.0.1 訪問
  
Alias /icons/ "/srv/www/icons/"  
語法: Alias fakename realname
設置目錄的別名,這樣當輸入http://localhost/icons/ 就可以訪問到/srv/www/icons/
注意icons結尾的"/" 應在fakename realname 成對出現,要麼全有,要麼全沒有.
有"/"時需要輸入http://localhost/icons/ 纔可以正常訪問

ScriptAlias /cgi-bin/ "/srv/www/cgi-bin/"
設置可執行程序別名,與Alias類似。
當Client請求Alias realname時,server直接以document形式傳送Client
而ScroptAlias則是server執行realname的script程序後將結果傳送給Client

服務器的狀態,信息:
通過http://localhost/server-status 訪問

    SetHandler server-status
    Order deny,allow
    Deny from all
    Allow from 127.0.0.1

通過http://localhost/server-info 訪問

    SetHandler server-info
    Order deny,allow
    Deny from all
    Allow from 127.0.0.1


.cgi .pl程序可執行的三種方法:
1:使用ScriptAlias,httpd.conf中加入:
ScriptAlias /my-cgi/ "/srv/www/cgi"
這樣就可以以http://localhost/my-cgi/xxx.cgi xxx.pl執行/srv/www/cgi/下的.cgi,.pl程序了。

2: 使用sethandler cgi-scripts,httpd.conf中加入:
Alias /my-cgi/ "/srv/www/cgi"

   Options ExecCGI
   Sethandler cgi-script


3:使用Options的ExecCGI屬性 :
將httpd.conf中的AddHandler cgi-script .cgi .pl 註釋拿掉,加上.pl
給予/srv/www/cgi/ 執行CGI權限:
Alias /my-cgi/ "/srv/www/cgi"

   Options ExecCGI
   Allowoverride none
   Order allow,deny
   allow from all


認證網頁:


   Options FollowSymlinks Indexes ExecCGI
   AllowOverride None
   Order Allow,Deny
   Allow From all
   AuthName "private directory "
   AuthType Basic
   AuthUserFile /etc/apace/apache.passwd
   Require valid-user


AuthNmae :      認證窗口上的標題
AuthType :      認證類型,apache有幾種認證方式,Basic爲最基本的。
AuthUserFIle : 認證密碼存放位置
Require : 認證檔案中允許使用的用戶
valid-user :   認證檔案中所有的用戶都可以使用通過認證進入該目錄
如只想允許某個用戶則使用 Require user username1 username2

建立認證密碼文件:
#cd /etc/apache/
#htpasswd -c apache.passwd blue
New password:
Re-type new password:
Adding password for user blue
#
-c : 如果沒有apache.passwd則創建它
增加認證用戶:
#htpasswd apache.passwd silence
....
#apachectl restart
#firefox http://localhost/my-cgi/
要求密碼纔可以進入嘍 :)

.htaccess 和 allowoverride :

.htaccess : 取代httpd.conf中對.htaccess所在目錄的設定。
AllowOverride :允許覆蓋設定的類型(All None FileInfo AuthConfig Limit)

設定每個用戶都可以建立自己的認證網頁:

1.確定httpd.conf中AccessFileName .htaccess 沒有被註釋掉
2.編輯httpd.conf加入AllowOverride AuthConfig,允許每個用戶通過.htaccess建立自己的認證網頁

   AllowOverride AuthConfig
    Order Allow,Deny
     Allow from all

3.用戶建立認證目錄,編寫.htaccess :
mkdir private
cd private/
echo " private page " >test.html
vi .htaccess
AuthName "private"
AuthType basic
AuthUserFIle /home/blue/blue.passwd
Require valid-user
建立密碼文件:
htpasswd -c blue.passwd blue
......
firefox http://localhost/~blue/private/test.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章