官术网_书友最值得收藏!

3.8 一個(gè)完整的httpd.conf文件

httpd.conf文件是Apache服務(wù)器的主要配置文件,安裝完畢后一般位于/etc/httpd/conf目錄下。這個(gè)配置文件是一個(gè)標(biāo)準(zhǔn)的Linux配置文件,文件中行首帶“#”符號(hào)的行是注釋行。這些注釋行對(duì)服務(wù)器軟件來說是沒有意義的,但是可以為網(wǎng)絡(luò)管理員提供文檔說明。管理員可以添加任意注釋,服務(wù)器分析httpd.conf文件時(shí)將忽略所有的注釋行。

除了注釋行和空行,服務(wù)器認(rèn)為其他所有行要么是一個(gè)完整命令,要么是一個(gè)命令的一部分。對(duì)于服務(wù)器來說,一個(gè)directive就是一個(gè)命令,它告訴服務(wù)器以某種特定的方式完成某一項(xiàng)特定的任務(wù)。下面給出一個(gè)完整的httpd.conf文件的示例。為了使讀者對(duì)httpd.conf文件的配置更加清楚,筆者把該文件中的英文注釋去掉,添加了中文注釋。

3.8.1 全局環(huán)境的設(shè)置

全局環(huán)境用于設(shè)置Apache的一些基本信息,如服務(wù)器根目錄、超時(shí)時(shí)間、文檔根目錄等。如果用戶對(duì)這些指令不是很清楚,可參考其他書籍了解其詳細(xì)功能和用法。

    //基于NCSA的服務(wù)器配置文件,由Rob McCool編寫
    //這是Apache服務(wù)器的主配置文件。包含了告訴服務(wù)器進(jìn)行何種操作的配置指令
    //可以訪問www.apache.org獲得更多詳細(xì)信息
    //不要只簡單地閱讀這些指令,一定要加以理解。如果你不確定,應(yīng)該到網(wǎng)上咨詢。
    ////// 第一部分:全局環(huán)境
    //
    // 本部分的指令將影響Apache的全局操作
    // 例如Apache能夠支持的并行請(qǐng)求數(shù)目等。
    //
    //控制了Server回送給客戶端的回應(yīng)頭域是否包含關(guān)于服務(wù)器OS類型和編譯進(jìn)的模塊描述信息
    ServerTokens OS
    //
    // 服務(wù)器配置文件、錯(cuò)誤顯示文件和日志文件等根目錄
    // 不要在目錄最后面加斜線“/”
    //
    ServerRoot "/etc/httpd"
    //保存服務(wù)器內(nèi)部的處理信息,httpd使用ScoreBoardFile來維護(hù)進(jìn)程的內(nèi)部數(shù)據(jù),因此通
    //常不需要改變這個(gè)參數(shù),除非管理員想在一臺(tái)計(jì)算機(jī)上運(yùn)行幾個(gè)Apache服務(wù)器,這時(shí)每
    //個(gè)Apache服務(wù)器都需要獨(dú)立地設(shè)置文件htt pd.conf,并使用不同的
    //ScoreBoardFile,ScoreBoardFile run/httpd.scoreboard
    //
    //Apache啟動(dòng)時(shí),服務(wù)器將把所有進(jìn)程ID號(hào)保存在PidFile指令指定的文件中。
    //
    PidFile run/httpd.pid
    //
    // 服務(wù)器的超時(shí)設(shè)置,表示對(duì)于某些事件,服務(wù)器在斷定請(qǐng)求失敗前等待的時(shí)間
    //
    Timeout 300
    //啟用HTTP持續(xù)作用,設(shè)置是否允許永久連接
    KeepAlive Off
    //
    //MaxKeepAliveRequests指令限制了當(dāng)啟用KeepAlive時(shí),每連接允許的請(qǐng)求數(shù)量。
    //如果將此值設(shè)為"0",將不限制請(qǐng)求的數(shù)目。我們建議最好將此值設(shè)為一個(gè)比較大的值,
    //以確保最優(yōu)的服務(wù)器性能。
    MaxKeepAliveRequests 100
    //
    // Apache在關(guān)閉連接前等待下一次請(qǐng)求的時(shí)間。一旦收到一個(gè)請(qǐng)求,
    // 超時(shí)值將會(huì)被設(shè)置為Timeout指令指定的值。
    //
    KeepAliveTimeout 15
    //
    //常規(guī)Server-Pool服務(wù)器池的大小(每分鐘M數(shù))
    //
    //封裝指令并根據(jù)指定的模塊是否存在為條件來決定是否進(jìn)行處理
    //選擇prefork MPM來實(shí)施基于流程的Web服務(wù)器。雖然基于流程的服務(wù)器
    //有一些速度較慢的性能,它們通過模塊來提供穩(wěn)定性和兼容性,這些模塊不支持線程。
    //為了改進(jìn)性能,服務(wù)器的父流程創(chuàng)建(fork)多個(gè)子流程并使它們能夠用于應(yīng)答請(qǐng)求。當(dāng)接收
    //到請(qǐng)求時(shí),服務(wù)器把其分配給子流程。如果沒有子流程可用,服務(wù)器創(chuàng)建新的子流程并
    //把它添加到庫中。但是,子流程的創(chuàng)建會(huì)導(dǎo)致延遲。當(dāng)配置這一MPM時(shí),管理員可以
    //限制啟動(dòng)時(shí)可以創(chuàng)建的子流程數(shù)、最大的子流程數(shù)等。這一MPM有利于形成一個(gè)穩(wěn)定的
    //Apache服務(wù)器,但同時(shí)會(huì)影響性能和占用內(nèi)存,因?yàn)閱蝹€(gè)流程的大小會(huì)占很大一部分。
    <IfModule prefork.c>
          StartServers      8
          MinSpareServers   5
          MaxSpareServers   20
          MaxClients      150
          MaxRequestsPerChild  1000
          </IfModule>
    //每個(gè)服務(wù)進(jìn)程的最大請(qǐng)求數(shù)
    <IfModule worker.c>
          StartServers        2
          MaxClients        150
          MinSpareThreads     25
          MaxSpareThreads     75
          ThreadsPerChild     25
          MaxRequestsPerChild  0
    </IfModule>
    //每個(gè)子進(jìn)程的最大請(qǐng)求數(shù)
    <IfModule perchild.c>
          NumServers          5
          StartThreads        5
          MinSpareThreads     5
          MaxSpareThreads     10
          MaxThreadsPerChild  20
          MaxRequestsPerChild  0
    </IfModule>
    //指定服務(wù)器偵聽的特定的IP地址或端口號(hào)。
    //Listen 12.34.56.78:80
    Listen 80
    //新版的Apache將各種模塊會(huì)用到的組件集中放在/etc/httpd/conf.d 文件中,
    //例如:mod_perl、mod_ssl、mod_php......等,因此在用Include指令指示
    //將其他配置文件引用到當(dāng)前配置文件
    Include conf.d/*.conf

3.8.2 動(dòng)態(tài)共享對(duì)象支持DSO的設(shè)置

為了能夠使用模塊功能,模塊通常以DSO(Dynamic Shared Object)的方式構(gòu)建,用戶應(yīng)該在httpd.conf文件中使用LoadModule指令,使得能夠在使用前獲得模塊的功能。靜態(tài)編譯模塊(在httpd-1中所列舉的)不要在此裝載。

    #
    # Dynamic Shared Object(DSO)Support
    #
    # To be able to use the functionality of a module which was built as a DSO
    # you have to place corresponding 'LoadModule' lines at this location so the
    # directives contained in it are actually available _before_ they are used.
    # Statically compiled modules(those listed by 'httpd -l')do not need
    # to be loaded here.
    #
    # Example:
    # LoadModule foo_module modules/mod_foo.so
    #
    LoadModule access_module modules/mod_access.so
    LoadModule auth_module modules/mod_auth.so
    LoadModule auth_anon_module modules/mod_auth_anon.so
    LoadModule auth_dbm_module modules/mod_auth_dbm.so
    LoadModule auth_digest_module modules/mod_auth_digest.so
    LoadModule include_module modules/mod_include.so
    LoadModule log_config_module modules/mod_log_config.so
    LoadModule env_module modules/mod_env.so
    LoadModule mime_magic_module modules/mod_mime_magic.so
    LoadModule cern_meta_module modules/mod_cern_meta.so
    LoadModule expires_module modules/mod_expires.so
    LoadModule headers_module modules/mod_headers.so
    LoadModule usertrack_module modules/mod_usertrack.so
    LoadModule unique_id_module modules/mod_unique_id.so
    LoadModule setenvif_module modules/mod_setenvif.so
    LoadModule mime_module modules/mod_mime.so
    LoadModule dav_module modules/mod_dav.so
    LoadModule status_module modules/mod_status.so
    LoadModule autoindex_module modules/mod_autoindex.so
    LoadModule asis_module modules/mod_asis.so
    LoadModule info_module modules/mod_info.so
    LoadModule dav_fs_module modules/mod_dav_fs.so
    LoadModule vhost_alias_module modules/mod_vhost_alias.so
    LoadModule negotiation_module modules/mod_negotiation.so
    LoadModule dir_module modules/mod_dir.so
    LoadModule imap_module modules/mod_imap.so
    LoadModule actions_module modules/mod_actions.so
    LoadModule speling_module modules/mod_speling.so
    LoadModule userdir_module modules/mod_userdir.so
    LoadModule alias_module modules/mod_alias.so
    LoadModule rewrite_module modules/mod_rewrite.so
    LoadModule proxy_module modules/mod_proxy.so
    LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
    LoadModule proxy_http_module modules/mod_proxy_http.so
    LoadModule proxy_connect_module modules/mod_proxy_connect.so
    <IfModule prefork.c>
          LoadModule cgi_module modules/mod_cgi.so
    </IfModule>
    <IfModule worker.c>
          LoadModule cgid_module modules/mod_cgid.so
    </IfModule>
    //擴(kuò)展?fàn)顟B(tài)控制Apache是否產(chǎn)生完整的狀態(tài)信息(設(shè)為on產(chǎn)生全部),如果設(shè)為Off
    //則產(chǎn)生基本的信息,當(dāng)與server-status頭有關(guān),默認(rèn)值為Off
    //ExtendedStatus On

3.8.3 主服務(wù)器設(shè)置

“主”服務(wù)器設(shè)置主要設(shè)置服務(wù)器的文檔目錄、用戶名及其組、管理員郵箱等。

    //第二部分
    //本節(jié)中指令的設(shè)置值,將被主服務(wù)所使用,主服務(wù)響應(yīng)那些沒有被<VirtualHost>所處理的請(qǐng)求,
    //這些值也為<VirtualHost>容器提供了默認(rèn)值,你可以在后面的文件中定義。
    //若你想使httpd以不同的用戶或組運(yùn)行,首先你必須用root賬戶運(yùn)行httpd,然后httpd將
    //會(huì)切換用戶。設(shè)置運(yùn)行httpd的用戶或組。
    //
    User apache
    Group apache
    //
    //ServerAdmin:郵箱地址,當(dāng)系統(tǒng)故障時(shí),可以給用戶發(fā)E-mail。此地址出現(xiàn)在那些
    //由服務(wù)器生成的頁面上,如出錯(cuò)文檔。例如:admin@ict.ac.cn
    //
    ServerAdmin admin@ict.ac.cn
    // ServerNaem定義了server名稱和端口號(hào),用以標(biāo)明自己的身份。通常可以自動(dòng)定義,
    //建議顯式地定義,避免起動(dòng)時(shí)出錯(cuò).
    //如果沒有正確定義主機(jī)的DNS,服務(wù)器產(chǎn)生的重定向?qū)⒉粫?huì)工作,同時(shí)參考
    //UseCanonicalName指令。
    //ServerName ict.ac.cn:80
    //如果沒有注冊(cè)DNS名字,請(qǐng)?jiān)谶@里輸入IP地址。可以在任何情況下使用IP地址,這也使用得重定
    //向變得敏感
    // UseCanonicalName:決定Apaceh如何構(gòu)建自定參考URL,并且SERVER_NAME及
    //SERVER_PORT變量當(dāng)設(shè)為Off時(shí),Apache將使用客戶端給出的域名和端口。
    //當(dāng)設(shè)為On時(shí),Apache將使用ServerName指令
    UseCanonicalName Off
    //DocumentRoot:服務(wù)器文檔放置目錄。在默認(rèn)情況下,所有的請(qǐng)求都從這里開始,
    //除了記號(hào)和別名將改指它處以外。
    DocumentRoot "/var/www/html"
    //
    //每個(gè)可供Apache訪問的目錄,可以配置成允許或禁止哪些服務(wù)和特征(包括其子目錄)
    //首先,我們定義一個(gè)默認(rèn)的非常嚴(yán)格的配置
    //
    <Directory />
          Options FollowSymLinks
          AllowOverride None
    </Directory>
    //注意,從這一點(diǎn)向前,你必須許可某些特殊的功能,所以如果某些功能未能如你所愿,
    //要確保你在在下述中啟用了該功能。
    //這將改變你對(duì)DocumentRoot的設(shè)置
    <Directory "/var/www/html">
    //可能的值為None,All或者任意組合
    //索引包括FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    //注意MultiViews被顯式地Options All,
    //選項(xiàng)指令既復(fù)雜又重要,http://httpd.apache.org/docs-2.0/mod/core.html
    //options
    //可了解更多詳情。
    //
        Options Indexes FollowSymLinks
    // AllowOverride 控制什么指令能夠加入到.htaccess中,可以是All,None,或者組合關(guān)鍵字
        AllowOverride None
    //
    //控制誰可以訪問此服務(wù)
    //
        Order allow,deny
        Allow from all
    </Directory>
    //使根目錄的aotoindex參數(shù)不可用,若沒有其他索引文件,
    //默認(rèn)的Welcome頁面將被顯示。
    <LocationMatch "^/$>
        Options -Indexes
        ErrorDocument 403 /error/noindex.html
    </LocationMatch>
    //UserDir: 用戶的home的名稱,當(dāng)接到~user的請(qǐng)求時(shí)。
    //請(qǐng)小心正確使用”/”. 在WinNT上,”Personal/My Website”是更合適的選擇
    // See also: http://httpd.apache.org/docs/misc/FAQ.html//forbidden
    //
    <IfModule mod_userdir.c>
    //默認(rèn)情況下UserDir是被禁止的,確保用戶的系統(tǒng)目錄不能訪問
        UserDir disable
    //為允許請(qǐng)求/'user目錄作為用戶公共網(wǎng)頁目錄,可以刪除上面的UserDir disable語句,同
    //時(shí)去掉下面語句的注釋。
    //UserDir public_html
    </IfModule>
    //控制UserDir目錄,以下是一個(gè)例子,這個(gè)目錄是只讀的
    #<Directory /home/*/public_html>
    #    AllowOverride FileInfo AuthConfig Limit
    #    Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
    #    <Limit GET POST OPTIONS>
    #       Order allow,deny
    #       Allow from all
    #    </Limit>
    #    <LimitExcept GET POST OPTIONS>
    #       Order deny,allow
    #       Deny from all
    #    </LimitExcept>
    #</Directory>
    #
    //DirectoryIndex: Apache服務(wù)器將要以一個(gè)目錄的形式響應(yīng)服務(wù)
    //index.html變量文件(一種映射)將直接傳送內(nèi)容。MultiViews
    //選項(xiàng)可以用于同樣的目的,但是要慢得多。
    DirectoryIndex index.html index.html.var
    // AccessFileName: 用來查找各個(gè)目錄下額外配置指令的配置文件名,
    //同時(shí)參考AllowOverride(允許重載)指令
    AccessFileName .htaccess
    //下面兩行,阻止Web客戶端訪問 .htaccess和htpasswd(訪問設(shè)定和密碼)的文件
    //
    <Files ~ "^\.ht">
        Order allow,deny
        Deny from all
    </Files>
    // TypesConfig,描述在何處找到mime類別
    //
    TypesConfig /etc/mime.types
    //如果服務(wù)器不能確定文檔的類型,將使用默認(rèn)的MIME類型,例如根據(jù)擴(kuò)展名
    //如果你的服務(wù)器主要包括text/html文檔,”text/plain”就是一個(gè)好的取值。
    //如果你的大多數(shù)內(nèi)容是binary(二進(jìn)制)的,如應(yīng)用程序或圖片,你可能希望使用
    //application/octet-stream,使得瀏覽器試圖顯示二進(jìn)制數(shù)據(jù),盡管它們是文本。
    DefaultType text/plain

3.8.4 設(shè)置日志管理

這部分設(shè)置一些與日志有關(guān)的配置,以及一些對(duì)客戶的控制。

    //mod_mime_magic模塊,允許服務(wù)器根據(jù)內(nèi)容提示來識(shí)別文件類型。
    //MIMEMagicFile指令告知模塊“內(nèi)容提示”應(yīng)到何處找。
    <IfModule mod_mime_magic.c>
    //   MIMEMagicFile /usr/share/magic.mime
        MIMEMagicFile conf/magic
    </IfModule>
    //HostNameLookups: 客戶日志或者僅其IP地址,如www.apache.org(on)或者
    //204.62.129.132(off).默認(rèn)值設(shè)為off比較好,如果希望將此置為on將意味著
    //第一次客戶請(qǐng)求都至少要查詢一次nameserver.
    //
    HostnameLookups Off
    // EnableSendfile: 控制內(nèi)核傳送文件是否支持(需要OS支持)。
    //默認(rèn)為on,如果使用NFS,則使用off
    //EnableSendfile off
    //ErrorLog: 出錯(cuò)日志文件如果你想為虛擬主機(jī)定義Errorlog指令,
    //則該虛擬主機(jī)的錯(cuò)誤信息將被記錄到這里
    ErrorLog logs/error_log
    //LogLever: 日志等級(jí),決定哪些級(jí)別的出錯(cuò)信息將被記錄,
    可能的值有ebug, info, notice, warn, error, crit, alert, emerg幾種。
    //
    LogLevel warn
    //下面指令定義帶有CustomLog指令的用戶的格式
    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
    //訪問日志文件的位置及格式
    //如果不在<VirtualHost>容器中定義任何日志文件,日志將會(huì)寫到這里。
    //否則,如果定義了日志文件,事務(wù)將被寫到相應(yīng)文件中。
    // CustomLog logs/access_log common
    CustomLog logs/access_log combined
    //若希望有代理和引用日志文件,去掉下面的注釋。
    //CustomLog logs/referer_log referer
    //CustomLog logs/agent_log agent
    //如果你喜歡用一個(gè)文件做訪問、代理和引用信息的日志,你可以使用下面的指令。
    //
    //CustomLog logs/access_log combined
    //可以加一行用以包含服務(wù)器版本和虛擬主機(jī)名稱
    //
    ServerSignature On

3.8.5 設(shè)置虛擬目錄

虛擬目錄是相對(duì)于Apache主目錄的相對(duì)路徑或絕對(duì)路徑的別名。虛擬目錄的設(shè)置有利于方便用戶在編寫網(wǎng)頁或cgi程序時(shí)對(duì)文件的引用。有了虛擬目錄,訪問某個(gè)目錄深度很深的文件時(shí)可以用一個(gè)簡短的虛擬目錄名代替其目錄名。

    //別名:這里可以無限制地增加你所需要的別名。
    //別名的格式是:Alias 別名 真實(shí)名稱
    Alias /icons/ "/var/www/icons/"
    //對(duì)該虛擬目錄設(shè)置
    <Directory "/var/www/icons">
        Options Indexes MultiViews
        AllowOverride None
        Order allow,deny
        Allow from all
    </Directory>
    // This should be changed to the ServerRoot/manual/.  The alias provides
    // the manual, even if you choose to move your DocumentRoot.  You may comment
    // this out if you do not care for the documentation.
    //對(duì)使用手冊(cè)文件所在目錄定義虛擬目錄
    Alias /manual "/var/www/manual"
    //設(shè)置該虛擬目錄的屬性
    <Directory "/var/www/manual">
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        Allow from all
    </Directory>
    <IfModule mod_dav_fs.c>
        // Location of the WebDAV lock database.
        DAVLockDB /var/lib/dav/lockdb
    </IfModule>
    //ScriptAlias 指令與 Alias 指令相同,只不過它還標(biāo)記該目錄包含
    //CGI或PHP指令文件(即執(zhí)行文件,如PHP解釋執(zhí)行文件)
    //
    ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
    <IfModule mod_cgid.c>
    //除了mod_cgid.c設(shè)置外,mod_cgid還可以為UNIX socket通信設(shè)置cgid。
    Scriptsock          run/httpd.cgid
    </IfModule>
    //
    //設(shè)置cgi-bin目錄的屬性
    //
    <Directory "/var/www/cgi-bin">
        AllowOverride None
        Options None
        Order allow,deny
        Allow from all
    </Directory>
    //對(duì)用戶請(qǐng)求的文檔進(jìn)行重定向,告知用戶到哪里獲取新的文檔。
    IndexOptions FancyIndexing VersionSort NameWidth=*
    #
    # AddIcon* directives tell the server which icon to show for different
    # files or filename extensions.  These are only displayed for
    # FancyIndexed directories.

3.8.6 設(shè)置MIME類型

設(shè)置MIME類型就是使Apache能夠識(shí)別的文件類型。除了從文件的后綴出發(fā)來判斷文件的MIME類型之外,Apache還可以進(jìn)一步分析文件的一些特征,來判斷文件的真實(shí)MIME類型。這個(gè)功能是由mod_mime_magic模塊實(shí)現(xiàn)的,它需要一個(gè)記錄各種MIME類型特征的文件,以進(jìn)行分析判斷。上面的設(shè)置是一個(gè)條件語句,如果載入了這個(gè)模塊,就必須指定相應(yīng)的標(biāo)志文件magic的位置。

    #
    AddIconByEncoding(CMP,/icons/compressed.gif)x-compress x-gzip
    AddIconByType(TXT,/icons/text.gif)text/*
    AddIconByType(IMG,/icons/image2.gif)image/*
    AddIconByType(SND,/icons/sound2.gif)audio/*
    AddIconByType(VID,/icons/movie.gif)video/*
    AddIcon /icons/binary.gif .bin .exe
    AddIcon /icons/binhex.gif .hqx
    AddIcon /icons/tar.gif .tar
    AddIcon /icons/world2.gif .wrl .wrl.gz .vrml .vrm .iv
    AddIcon /icons/compressed.gif .Z .z .tgz .gz .zip
    AddIcon /icons/a.gif .ps .ai .eps
    AddIcon /icons/layout.gif .html .shtml .htm .pdf
    AddIcon /icons/text.gif .txt
    AddIcon /icons/c.gif .c
    AddIcon /icons/p.gif .pl .py
    AddIcon /icons/f.gif .for
    AddIcon /icons/dvi.gif .dvi
    AddIcon /icons/uuencoded.gif .uu
    AddIcon /icons/script.gif .conf .sh .shar .csh .ksh .tcl
    AddIcon /icons/tex.gif .tex
    AddIcon /icons/bomb.gif core
    AddIcon /icons/back.gif ..
    AddIcon /icons/hand.right.gif README
    AddIcon /icons/folder.gif ^^DIRECTORY^^
    AddIcon /icons/blank.gif ^^BLANKICON^^
    //默認(rèn)圖標(biāo)就是當(dāng)文件沒有顯式指明圖標(biāo)時(shí)顯示的一個(gè)圖標(biāo)。
    //
    DefaultIcon /icons/unknown.gif
    //AddDescription指令允許你對(duì)服務(wù)器文件給出一個(gè)更短的描述。
    #AddDescription "GZIP compressed document" .gz
    #AddDescription "tar archive" .tar
    #AddDescription "GZIP compressed tar archive" .tgz

3.8.7 文檔管理和語言管理

本部分定義各種Readme文檔、錯(cuò)誤信息文檔等對(duì)應(yīng)的HTML文件,以及給Apache增加支持的語言。

    // 指明Readme文件的文件名
    ReadmeName README.html
    HeaderName HEADER.html
    // IndexIgnore指令為一組忽略的文件,可以使用通配符
    IndexIgnore .??* *~ *// HEADER* README* RCS CVS *,v *,t
    // AddEncoding指令允許你用特定瀏覽器時(shí)能解壓縮特定的文件類型
    AddEncoding x-compress Z
    AddEncoding x-gzip gz tgz
    // DefaultLanguage指示網(wǎng)頁顯示的默認(rèn)語言。
    // AddLanguage指令允許你指定特定文檔的特定語言。
    # DefaultLanguage nl
    #
    //加入語言支持
    AddLanguage da .dk
    AddLanguage nl .nl
    AddLanguage en .en
    AddLanguage et .et
    AddLanguage fr .fr
    AddLanguage de .de
    AddLanguage he .he
    AddLanguage el .el
    AddLanguage it .it
    AddLanguage ja .ja
    AddLanguage pl .po
    AddLanguage kr .kr
    AddLanguage pt .pt
    AddLanguage nn .nn
    AddLanguage no .no
    AddLanguage pt-br .pt-br
    AddLanguage ltz .ltz
    AddLanguage ca .ca
    AddLanguage es .es
    AddLanguage sv .se
    AddLanguage cz .cz
    AddLanguage ru .ru
    AddLanguage tw .tw
    AddLanguage zh-tw .tw
    AddLanguage hr .hr
    //
    // LanguagePriority指令指定語言的優(yōu)先級(jí)
    //
    LanguagePriority en da nl et fr de el it ja kr no pl pt pt-br ltz ca es sv tw
    // ForceLanguagePriority指令允許你在沒有語言匹配時(shí)提供一個(gè)結(jié)果頁面,而不是
    //一組頁面
    ForceLanguagePriority Prefer Fallback
    //指定默認(rèn)字符集
    AddDefaultCharset ISO-8859-1
    //常用字符集的擴(kuò)展文件名
    AddCharset ISO-8859-1  .iso8859-1  .latin1
    AddCharset ISO-8859-2  .iso8859-2  .latin2 .cen
    AddCharset ISO-8859-3  .iso8859-3  .latin3
    AddCharset ISO-8859-4  .iso8859-4  .latin4
    AddCharset ISO-8859-5  .iso8859-5  .latin5 .cyr .iso-ru
    AddCharset ISO-8859-6  .iso8859-6  .latin6 .arb
    AddCharset ISO-8859-7  .iso8859-7  .latin7 .grk
    AddCharset ISO-8859-8  .iso8859-8  .latin8 .heb
    AddCharset ISO-8859-9  .iso8859-9  .latin9 .trk
    AddCharset ISO-2022-JP .iso2022-jp .jis
    AddCharset ISO-2022-KR .iso2022-kr .kis
    AddCharset ISO-2022-CN .iso2022-cn .cis
    AddCharset Big5       .Big5      .big5
    // For russian, more than one charset is used(depends on client, mostly):
    AddCharset WINDOWS-1251 .cp-1251   .win-1251
    AddCharset CP866      .cp866
    AddCharset KOI8-r     .koi8-r .koi8-ru
    AddCharset KOI8-ru    .koi8-uk .ua
    AddCharset ISO-10646-UCS-2 .ucs2
    AddCharset ISO-10646-UCS-4 .ucs4
    AddCharset UTF-8      .utf8
    //下面字符集不是標(biāo)準(zhǔn),但是廣泛使用
    AddCharset GB2312     .gb2312 .gb
    AddCharset utf-7      .utf7
    AddCharset utf-8      .utf8
    AddCharset big5       .big5 .b5
    AddCharset EUC-TW     .euc-tw
    AddCharset EUC-JP     .euc-jp
    AddCharset EUC-KR     .euc-kr
    AddCharset shift_jis   .sjis
    // AddType指令允許你增加或覆蓋MIME配置文件的mime類型。
    AddType application/x-tar .tgz
    // AddHandler指令允許你為特定擴(kuò)展文件名映射到特定處理
    //AddHandler cgi-script .cgi
    //
    //帶HTTP頭的文件
    //AddHandler send-as-is asis
    //
    // For server-parsed imagemap files:
    //處理服務(wù)器端解析的imagemap文件
    AddHandler imap-file  map
    AddHandler type-map var
    // AddOutputFilter指令指示服務(wù)器端執(zhí)行的文件擴(kuò)展名
    //
    AddOutputFilter INCLUDES .shtml
    // Action指令允許你定義當(dāng)文件匹配時(shí)執(zhí)行的腳本。
    // 格式: Action media/type /cgi-script/location
    // 格式: Action handler-name /cgi-script/location
    //
    //配置錯(cuò)誤響應(yīng)
    // 例如:
    #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
    #
    //加入下面一行,可以不改變默認(rèn)錯(cuò)誤文件而更改所有錯(cuò)誤信息顯示形式。
    #   Alias /error/include/ "/your/include/path/"
    #
    //增加自己的錯(cuò)誤顯示文件
    Alias /error/ "/var/www/error/"
    <IfModule mod_negotiation.c>
    <IfModule mod_include.c>
        <Directory "/var/www/error">
          AllowOverride None
          Options IncludesNoExec
          AddOutputFilter Includes html
          ler type-map var
          Order allow,deny
          Allow from all
          LanguagePriority en es de fr
          ForceLanguagePriority Prefer Fallback
        </Directory>
    //下面是各種錯(cuò)誤發(fā)生時(shí)將顯示的錯(cuò)誤頁面文件名
        ErrorDocument 400 /error/HTTP_BAD_REQUEST.html.var
        ErrorDocument 401 /error/HTTP_UNAUTHORIZED.html.var
        ErrorDocument 403 /error/HTTP_FORBIDDEN.html.var
        ErrorDocument 404 /error/HTTP_NOT_FOUND.html.var
        ErrorDocument 405 /error/HTTP_METHOD_NOT_ALLOWED.html.var
        ErrorDocument 408 /error/HTTP_REQUEST_TIME_OUT.html.var
        ErrorDocument 410 /error/HTTP_GONE.html.var
        ErrorDocument 411 /error/HTTP_LENGTH_REQUIRED.html.var
        ErrorDocument 412 /error/HTTP_PRECONDITION_FAILED.html.var
        ErrorDocument 413 /error/HTTP_REQUEST_ENTITY_TOO_LARGE.html.var
        ErrorDocument 414 /error/HTTP_REQUEST_URI_TOO_LARGE.html.var
        ErrorDocument 415 /error/HTTP_SERVICE_UNAVAILABLE.html.var
        ErrorDocument 500 /error/HTTP_INTERNAL_SERVER_ERROR.html.var
        ErrorDocument 501 /error/HTTP_NOT_IMPLEMENTED.html.var
        ErrorDocument 502 /error/HTTP_BAD_GATEWAY.html.var
        ErrorDocument 503 /error/HTTP_SERVICE_UNAVAILABLE.html.var
        ErrorDocument 506 /error/HTTP_VARIANT_ALSO_VARIES.html.var
    </IfModule>
    </IfModule>
    //下面指令改變正常HTTP相應(yīng)行為。
    //
    BrowserMatch "Mozilla/2" nokeepalive
    BrowserMatch "MSIE 4\.0b2;" nokeepalive downgrade-1.0 force-response-1.0
    BrowserMatch "RealPlayer 4\.0" force-response-1.0
    BrowserMatch "Java/1\.0" force-response-1.0
    BrowserMatch "JDK/1\.0" force-response-1.0
    //下面指令禁止重定向
    //
    BrowserMatch "Microsoft Data Access Internet Publishing Provider" redirect- carefully
    BrowserMatch "^WebDrive" redirect-carefully
    //允許服務(wù)器狀態(tài)報(bào)告
    //
    #<Location /server-status>
    #    SetHandler server-status
    #    Order deny,allow
    #    Deny from all
    #    Allow from .your-domain.com
    #</Location>
    //允許遠(yuǎn)程服務(wù)器配置報(bào)告。
    //
    #<Location /server-info>
    #    SetHandler server-info
    #    Order deny,allow
    #    Deny from all
    #    Allow from .your-domain.com
    #</Location>
    //代理服務(wù)器設(shè)置,如果想啟用代理服務(wù)器,去掉下面的注釋
    #<IfModule mod_proxy.c>
    #ProxyRequests On
    #
    #<Proxy *>
    #    Order deny,allow
    #    Deny from all
    #    Allow from .your-domain.com
    #</Proxy>
    //允許或禁止處理HTTP/1.1。
    # Set to one of: Off | On | Full | Block
    #
    #ProxyVia On
    //允許緩存
    #
    #CacheRoot "/etc/httpd/proxy"
    #CacheSize 5
    #CacheGcInterval 4
    #CacheMaxExpire 24
    #CacheLastModifiedFactor 0.1
    #CacheDefaultExpire 1
    #NoCache a-domain.com another-domain.edu joes.garage-sale.com
    #</IfModule>
    # End of proxy directives.

3.8.8 設(shè)置虛擬主機(jī)

設(shè)置虛擬主機(jī)可以允許一臺(tái)物理機(jī)器上允許多個(gè)Apache服務(wù)器。

    // 第三部分:虛擬主機(jī)
    //
    //虛擬主機(jī):有兩種方法在Apache服務(wù)器上設(shè)置虛擬主機(jī)。可以使用一個(gè)IP
    //地址對(duì)應(yīng)一個(gè)CNAME(Computer Name)的方法,也可以一個(gè)IP地址對(duì)應(yīng)
    //多個(gè)CNAME。Apache有不同的指令集處理這些選項(xiàng)的每一種。
    //基于用戶名的虛擬主機(jī)
    //
    #NameVirtualHost *
    //
    //虛擬主機(jī)舉例。
    //
    #<VirtualHost *>
    #    ServerAdmin webmaster@dummy-host.example.com
    #    DocumentRoot /www/docs/dummy-host.example.com
    #    ServerName dummy-host.example.com
    #    ErrorLog logs/dummy-host.example.com-error_log
    #    CustomLog logs/dummy-host.example.com-access_log common
    #</VirtualHost>
主站蜘蛛池模板: 五台县| 海宁市| 峨山| 景东| 登封市| 鱼台县| 岗巴县| 烟台市| 松阳县| 通化市| 平顶山市| 拉萨市| 西盟| 达日县| 蓬安县| 旬邑县| 来宾市| 浦北县| 韶山市| 闽侯县| 封开县| 东平县| 永定县| 武安市| 雷山县| 九江市| 东宁县| 桃园市| 凉山| 武宣县| 房山区| 利川市| 肃宁县| 临武县| 南投县| 兴业县| 堆龙德庆县| 临颍县| 岐山县| 饶阳县| 滦平县|