亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Verzeichnis suchen
首頁 版本說明 從1.3升級到2.0 編譯時配置的改變 運行時配置的改變 雜項變化 第三方模塊 從 2.0 升級到 2.2 編譯時配置的改變 運行時配置的改變 雜項變化 第三方模塊 Apache 2.1/2.2 版本的新特性 核心增強 模塊增強 程序增強 針對模塊開發(fā)者的變化 Apache 2.0 版本的新特性 核心的增強 模塊的增強 Apache許可證 參考手冊 編譯與安裝 針對心急者的概述 要求 下載 解壓 配置源代碼樹 編譯 安裝 配置 測試 升級 啟動 Apache是怎樣啟動的 啟動時發(fā)生錯誤 隨系統(tǒng)啟動時啟動 額外信息 停止與重新啟動 簡介 立即停止 優(yōu)雅重啟 立即重啟 優(yōu)雅停止 附錄:信號和競爭條件 運行時配置指令 主配置文件 配置文件的語法 模塊 指令的作用域 .htaccess文件 配置段 配置段(容器)的類型 文件系統(tǒng)和網(wǎng)絡(luò)空間 虛擬主機 代理 允許使用哪些指令? 配置段的合并 內(nèi)容緩沖 簡介 緩沖概述 安全方面的考慮 文件句柄緩沖 內(nèi)存緩沖 磁盤緩沖 服務(wù)器全局配置 服務(wù)器標識 文件定位 限制資源的使用 日志文件 安全警告 錯誤日志 訪問日志 日志滾動 管道日志 虛擬主機 其他日志文件 從URL到文件系統(tǒng)的映射 相關(guān)模塊和指令 DocumentRoot DocumentRoot以外的文件 用戶目錄 URL重定向 反向代理 重寫引擎 File Not Found 安全方面的提示 保持不斷更新和升級 ServerRoot目錄的權(quán)限 服務(wù)器端包含 關(guān)于CGI 未指定為腳本的CGI 指定為腳本的CGI 其他動態(tài)內(nèi)容的來源 系統(tǒng)設(shè)置的保護 默認配置下服務(wù)器文件的保護 觀察日志文件 動態(tài)共享對象(DSO) 實現(xiàn) 用法概要 背景知識 優(yōu)點和缺點 內(nèi)容協(xié)商 關(guān)于內(nèi)容協(xié)商 Apache中的內(nèi)容協(xié)商 協(xié)商的方法 打亂品質(zhì)值 透明內(nèi)容協(xié)商的擴展 超鏈和名稱轉(zhuǎn)換說明 緩沖說明 更多信息 自定義錯誤響應(yīng) 行為 配置 自定義錯誤響應(yīng)與重定向 地址和端口綁定 概述 針對IPv6的特殊考慮 怎樣與虛擬主機協(xié)同工作 多路處理模塊(MPM) 簡介 選擇一個MPM 默認的MPM 環(huán)境變量 設(shè)置環(huán)境變量 使用環(huán)境變量 用于特殊目的的環(huán)境變量 示例 處理器的使用 什么是處理器? 例子 程序員注意事項 過濾器 Apache2中的過濾器 智能過慮 使用過濾器 CGI腳本的Suexec執(zhí)行 開始之前 suEXEC的安全模型 配置和安裝suEXEC 啟用和禁用suEXEC 使用suEXEC 調(diào)試suEXEC 謹防Jabberwock:警告和舉例 性能調(diào)整 硬件和操作系統(tǒng) 運行時的配置 編譯時的配置 附錄:蹤跡的詳細分析 URL重寫指南 mod_rewrite簡介 實踐方案 URL的規(guī)劃 內(nèi)容的處理 對訪問的限制 其他 虛擬主機文檔 總述 虛擬主機支持 配置指令 基于主機名的虛擬主機 基于域名的虛擬主機和基于IP的虛擬主機比較 使用基于域名的虛擬主機 與舊版瀏覽器的兼容性 基于IP地址的虛擬主機 系統(tǒng)需求 如何配置Apache 設(shè)置多個守護進程 配置擁有多個虛擬主機的單一守護進程 動態(tài)配置大量虛擬主機 動機 概述 簡單的動態(tài)虛擬主機 一個實際的個人主頁系統(tǒng) 在同一個服務(wù)器上架設(shè)多個主機的虛擬系統(tǒng) 更為有效的基于IP地址的虛擬主機 使用老版本的Apache 使用mod_rewrite實現(xiàn)簡單的動態(tài)虛擬主機 使用mod_rewrite的個人主頁系統(tǒng) 使用獨立的虛擬主機配置文件 虛擬主機的普通配置示例 在一個IP地址上運行多個基于域名的web站點 在多于一個IP的情況下使用基于域名的虛擬主機 在不同的IP的地址(比如一個內(nèi)部和一個外部地址)上提供相同的內(nèi)容 在不同的端口上運行不同的站點 建立基于IP的虛擬主機 混用基于端口和基于IP的虛擬主機 混用基于域名和基于IP的虛擬主機 將虛擬主機和代理模塊一起使用 使用默認虛擬主機 將一個基于域名的虛擬主機移植為一個基于IP的虛擬主機 使用ServerPath指令 深入討論虛擬主機的匹配 解析配置文件 虛擬主機匹配 小技巧 文件描述符限制 關(guān)于DNS和Apache 一個簡單示例 拒絕服務(wù) "主服務(wù)器"地址 避免這些問題的小技巧 附錄:進一步的提示 常見問題 概述 SSL/TLS 加密 概述 文檔 mod_ssl 緒論 密碼技術(shù) 證書 安全套接字層(SSL) 參考 兼容性 配置指令 環(huán)境變量 自定義日志功能 如何... 加密方案和強制性高等級安全 客戶認證和訪問控制 常見問題解答 About The Module Installation Configuration Certificates The SSL Protocol mod_ssl Support 如何.../指南 概述 認證 相關(guān)模塊和指令 簡介 先決條件 啟用認證 允許多人訪問 可能存在的問題 其他認證方法 更多信息 CGI動態(tài)頁面 簡介 配置Apache以允許CGI 編寫CGI程序 程序還是不能運行! 幕后是怎樣操作的? CGI模塊/庫 更多信息 服務(wù)器端包含 簡介 什么是SSI? 配置服務(wù)器以允許SSI 基本SSI指令 附加的例子 我還能設(shè)置其它什么? 執(zhí)行命令 高級SSI技術(shù) 總結(jié) .htaccess文件 .htaccess文件 工作原理和使用方法 (不)使用.htaccess文件的場合 指令的生效 認證舉例 服務(wù)器端包含(SSI)舉例 CGI舉例 疑難解答 用戶網(wǎng)站目錄 用戶網(wǎng)站目錄 用UserDir設(shè)置文件路徑 限定哪些用戶可以使用此功能 啟用對每個用戶都有效的cgi目錄 允許用戶改變配置 對特定平臺的說明 概述 Microsoft Windows 其他平臺 在Microsoft Windows中使用Apache 對操作系統(tǒng)的要求 下載 Apache for Windows 安裝 Apache for Windows 配置 Apache for Windows 以服務(wù)方式運行 Apache for Windows 作為控制臺程序運行Apache 測試安裝 編譯Windows下的Apache 系統(tǒng)要求 命令行編譯 Developer Studio集成開發(fā)環(huán)境的工作區(qū)編譯 項目組件 在Novell NetWare平臺上使用Apache Requirements Downloading Apache for NetWare Installing Apache for NetWare Running Apache for NetWare Configuring Apache for NetWare Compiling Apache for NetWare 在HP-UX中運行Apache The Apache EBCDIC Port Overview of the Apache EBCDIC Port Design Goals Technical Solution Porting Notes Document Storage Notes Apache Modules' Status Third Party Modules' Status 服務(wù)器與支持程序 概述 httpd 語法 選項 ab 語法 選項 Bugs apachectl 語法 選項 apxs 語法 選項 舉例 configure 語法 選項 環(huán)境變量 dbmmanage 語法 選項 Bugs htcacheclean 語法 選項 返回值 htdbm 語法 選項 Bugs 返回值 舉例 安全方面的考慮 限制 htdigest 語法 選項 htpasswd 語法 選項 返回值 舉例 安全方面的考慮 限制 logresolve 語法 選項 rotatelogs 語法 選項 Portability suexec 語法 選項 其他程序 log_server_status split-logfile 雜項文檔 概述 相關(guān)標準 HTTP推薦標準 HTML推薦標準 認證 語言/國家代碼 Apache 模塊 描述模塊的術(shù)語 說明 狀態(tài) 源代碼文件 模塊標識符 兼容性 描述指令的術(shù)語 說明 語法 默認值(Default) 作用域(Context) 覆蓋項(Override) 狀態(tài) 模塊(Module) 兼容性(Compatibility) Apache核心(Core)特性 AcceptFilter AcceptPathInfo AccessFileName AddDefaultCharset AddOutputFilterByType AllowEncodedSlashes AllowOverride AuthName AuthType CGIMapExtension ContentDigest DefaultType <Directory> <DirectoryMatch> DocumentRoot EnableMMAP EnableSendfile ErrorDocument ErrorLog FileETag <Files> <FilesMatch> ForceType HostnameLookups <IfDefine> <IfModule> Include KeepAlive KeepAliveTimeout <Limit> <LimitExcept> LimitInternalRecursion LimitRequestBody LimitRequestFields LimitRequestFieldSize LimitRequestLine LimitXMLRequestBody <Location> <LocationMatch> LogLevel MaxKeepAliveRequests NameVirtualHost Options Require RLimitCPU RLimitMEM RLimitNPROC Satisfy ScriptInterpreterSource ServerAdmin ServerAlias ServerName ServerPath ServerRoot ServerSignature ServerTokens SetHandler SetInputFilter SetOutputFilter TimeOut TraceEnable UseCanonicalName UseCanonicalPhysicalPort <VirtualHost> Apache MPM 公共指令 AcceptMutex CoreDumpDirectory EnableExceptionHook GracefulShutdownTimeout Group Listen ListenBackLog LockFile MaxClients MaxMemFree MaxRequestsPerChild MaxSpareThreads MinSpareThreads PidFile ReceiveBufferSize ScoreBoardFile SendBufferSize ServerLimit StartServers StartThreads ThreadLimit ThreadsPerChild ThreadStackSize User Apache MPM beos MaxRequestsPerThread CoreDumpDirectory Group Listen ListenBacklog MaxClients MaxMemFree MaxSpareThreads MinSpareThreads PidFile ReceiveBufferSize ScoreBoardFile SendBufferSize StartThreads User Apache MPM event AcceptMutex CoreDumpDirectory EnableExceptionHook Group Listen ListenBacklog LockFile MaxClients MaxMemFree MaxRequestsPerChild MaxSpareThreads MinSpareThreads PidFile ScoreBoardFile SendBufferSize ServerLimit StartServers ThreadLimit ThreadsPerChild ThreadStackSize User Apache MPM netware MaxThreads Listen ListenBacklog MaxMemFree MaxRequestsPerChild MaxSpareThreads MinSpareThreads ReceiveBufferSize SendBufferSize StartThreads ThreadStackSize Apache MPM os2 Group Listen ListenBacklog MaxRequestsPerChild MaxSpareThreads MinSpareThreads PidFile ReceiveBufferSize SendBufferSize StartServers User Apache MPM prefork 工作方式 MaxSpareServers MinSpareServers AcceptMutex CoreDumpDirectory EnableExceptionHook Group Listen ListenBacklog LockFile MaxClients MaxMemFree MaxRequestsPerChild PidFile ReceiveBufferSize ScoreBoardFile SendBufferSize ServerLimit StartServers User Apache MPM winnt Win32DisableAcceptEx CoreDumpDirectory Listen ListenBacklog MaxMemFree MaxRequestsPerChild PidFile ReceiveBufferSize ScoreBoardFile SendBufferSize ThreadLimit ThreadsPerChild ThreadStackSize Apache MPM worker 工作方式 AcceptMutex CoreDumpDirectory EnableExceptionHook Group Listen ListenBacklog LockFile MaxClients MaxMemFree MaxRequestsPerChild MaxSpareThreads MinSpareThreads PidFile ReceiveBufferSize ScoreBoardFile SendBufferSize ServerLimit StartServers ThreadLimit ThreadsPerChild ThreadStackSize User Apache Module mod_actions Action指令 Script指令 Apache Module mod_alias 處理順序 Alias AliasMatch Redirect RedirectMatch RedirectPermanent RedirectTemp ScriptAlias ScriptAliasMatch Apache Module mod_asis 用法 Apache Module mod_auth_basic AuthBasicAuthoritative AuthBasicProvider Apache Module mod_auth_digest 使用摘要認證 配合 MS Internet Explorer 6 工作 AuthDigestAlgorithm AuthDigestDomain AuthDigestNcCheck AuthDigestNonceFormat AuthDigestNonceLifetime AuthDigestProvider AuthDigestQop AuthDigestShmemSize Apache Module mod_authn_alias 示例 <AuthnProviderAlias> Apache Module mod_authn_anon 示例 Anonymous Anonymous_LogEmail Anonymous_MustGiveEmail Anonymous_NoUserID Anonymous_VerifyEmail Apache Module mod_authn_dbd 配置示例 AuthDBDUserPWQuery AuthDBDUserRealmQuery Apache Module mod_authn_dbm AuthDBMType AuthDBMUserFile Apache Module mod_authn_default AuthDefaultAuthoritative Apache Module mod_authn_file AuthUserFile Apache Module mod_authnz_ldap Contents Operation The require Directives 舉例 Using TLS Using SSL Using Microsoft FrontPage with mod_authnz_ldap AuthLDAPBindDN AuthLDAPBindPassword AuthLDAPCharsetConfig AuthLDAPCompareDNOnServer AuthLDAPDereferenceAliases AuthLDAPGroupAttribute AuthLDAPGroupAttributeIsDN AuthLDAPRemoteUserIsDN AuthLDAPUrl AuthzLDAPAuthoritative Apache Module mod_authz_dbm AuthDBMGroupFile AuthzDBMAuthoritative AuthzDBMType Apache Module mod_authz_default AuthzDefaultAuthoritative Apache Module mod_authz_groupfile AuthGroupFile AuthzGroupFileAuthoritative Apache Module mod_authz_host Allow Deny Order Apache Module mod_authz_owner 配置示例 AuthzOwnerAuthoritative Apache Module mod_authz_user AuthzUserAuthoritative Apache Module mod_autoindex Autoindex Request Query Arguments AddAlt AddAltByEncoding AddAltByType AddDescription AddIcon AddIconByEncoding AddIconByType DefaultIcon HeaderName IndexIgnore IndexOptions IndexOrderDefault IndexStyleSheet ReadmeName Apache Module mod_cache Related Modules and Directives 配置示例 CacheDefaultExpire CacheDisable CacheEnable CacheIgnoreCacheControl CacheIgnoreHeaders CacheIgnoreNoLastMod CacheLastModifiedFactor CacheMaxExpire CacheStoreNoStore CacheStorePrivate Apache Module mod_cern_meta MetaDir MetaFiles MetaSuffix Apache Module mod_cgi CGI 環(huán)境變量 CGI 腳本的調(diào)試 ScriptLog ScriptLogBuffer ScriptLogLength Apache Module mod_cgid ScriptSock ScriptLog ScriptLogBuffer ScriptLogLength Apache Module mod_charset_lite Common Problems CharsetDefault CharsetOptions CharsetSourceEnc Apache Module mod_dav Enabling WebDAV Security Issues Complex Configurations Dav DavDepthInfinity DavMinTimeout Apache Module mod_dav_fs DavLockDB Apache Module mod_dav_lock DavGenericLockDB Apache Module mod_dbd Connection Pooling Apache DBD API SQL Prepared Statements DBDExptime DBDKeep DBDMax DBDMin DBDParams DBDPersist DBDPrepareSQL DBDriver Apache Module mod_deflate 配置舉例 啟用壓縮 代理服務(wù)器 DeflateBufferSize DeflateCompressionLevel DeflateFilterNote DeflateMemLevel DeflateWindowSize Apache Module mod_dir DirectoryIndex DirectorySlash Apache Module mod_disk_cache CacheDirLength CacheDirLevels CacheMaxFileSize CacheMinFileSize CacheRoot Apache Module mod_dumpio 啟用dumpio支持 DumpIOInput DumpIOOutput Apache Module mod_echo ProtocolEcho Apache Module mod_env PassEnv SetEnv UnsetEnv Apache Module mod_example Compiling the example module Using the mod_example Module Example Apache Module mod_expires 交替間隔語法 ExpiresActive ExpiresByType ExpiresDefault Apache Module mod_ext_filter 舉例 ExtFilterDefine ExtFilterOptions Apache Module mod_file_cache Using mod_file_cache CacheFile MMapFile Apache Module mod_filter Smart Filtering Filter Declarations Configuring the Chain Examples Protocol Handling FilterChain FilterDeclare FilterProtocol FilterProvider FilterTrace Apache Module mod_headers 處理順序 前處理和后處理 舉例 Header RequestHeader Apache Module mod_ident IdentityCheck IdentityCheckTimeout Apache Module mod_imagemap New Features Imagemap File Example Mapfile Referencing your mapfile ImapBase ImapDefault ImapMenu Apache Module mod_include Enabling Server-Side Includes PATH_INFO with Server Side Includes Basic Elements Include Variables Variable Substitution Flow Control Elements SSIEndTag SSIErrorMsg SSIStartTag SSITimeFormat SSIUndefinedEcho XBitHack Apache Module mod_info 安全問題 選擇哪些信息可以被顯示 已知的局限 AddModuleInfo Apache Module mod_isapi 用法 附加注釋 程序員注記 ISAPIAppendLogToErrors ISAPIAppendLogToQuery ISAPICacheFile ISAPIFakeAsync ISAPILogNotSupported ISAPIReadAheadBuffer Apache Module mod_ldap 示例配置 LDAP 連接池 LDAP 緩沖 使用SSL/TLS SSL/TLS 證書 LDAPCacheEntries LDAPCacheTTL LDAPConnectionTimeout LDAPOpCacheEntries LDAPOpCacheTTL LDAPSharedCacheFile LDAPSharedCacheSize LDAPTrustedClientCert LDAPTrustedGlobalCert LDAPTrustedMode LDAPVerifyServerCert Apache Module mod_log_config 定制日志文件格式 安全考慮 BufferedLogs CookieLog CustomLog LogFormat TransferLog Apache Module mod_log_forensic 定制日志文件格式 安全考慮 ForensicLog Apache Module mod_logio 定制日志文件格式 Apache Module mod_mem_cache MCacheMaxObjectCount MCacheMaxObjectSize MCacheMaxStreamingBuffer MCacheMinObjectSize MCacheRemovalAlgorithm MCacheSize Apache Module mod_mime 帶多擴展名的文件 內(nèi)容編碼 字符集和語言 AddCharset AddEncoding AddHandler AddInputFilter AddLanguage AddOutputFilter AddType DefaultLanguage ModMimeUsePathInfo MultiviewsMatch RemoveCharset RemoveEncoding RemoveHandler RemoveInputFilter RemoveLanguage RemoveOutputFilter RemoveType TypesConfig Apache Module mod_mime_magic "Magic文件"的格式 性能問題 注意 MimeMagicFile Apache Module mod_negotiation 類型表 MultiViews CacheNegotiatedDocs ForceLanguagePriority LanguagePriority Apache Module mod_nw_ssl NWSSLTrustedCerts NWSSLUpgradeable SecureListen Apache Module mod_proxy 正向和反向代理 簡單示例 控制對代理服務(wù)器的訪問 緩慢啟動 局域網(wǎng)代理 協(xié)議調(diào)整 請求體 AllowCONNECT NoProxy <Proxy> ProxyBadHeader ProxyBlock ProxyDomain ProxyErrorOverride ProxyIOBufferSize <ProxyMatch> ProxyMaxForwards ProxyPass ProxyPassReverse ProxyPassReverseCookieDomain ProxyPassReverseCookiePath ProxyPreserveHost ProxyReceiveBufferSize ProxyRemote ProxyRemoteMatch ProxyRequests ProxyTimeout ProxyVia Apache Module mod_proxy_ajp Overview of the protocol Basic Packet Structure Request Packet Structure Response Packet Structure Apache Module mod_proxy_balancer Load balancer scheduler algorithm Request Counting Algorithm Weighted Traffic Counting Algorithm Enabling Balancer Manager Support Apache Module mod_proxy_connect Apache Module mod_proxy_ftp 為什么xxx類型的文件不能從FTP下載? 如何強制文件xxx使用FTP的ASCII形式下載? 我如何使用FTP上傳? 我如何能訪問我自己home目錄以外的FTP文件? 我如何才能在瀏覽器的URL框中隱藏FTP的明文密碼? Apache Module mod_proxy_http Apache Module mod_rewrite 特殊字符的引用 環(huán)境變量 實用方案 RewriteBase RewriteCond RewriteEngine RewriteLock RewriteLog RewriteLogLevel RewriteMap RewriteOptions RewriteRule Apache Module mod_setenvif BrowserMatch BrowserMatchNoCase SetEnvIf SetEnvIfNoCase Apache Module mod_so 為Windows創(chuàng)建可加載模塊 LoadFile LoadModule Apache Module mod_speling CheckSpelling Apache Module mod_ssl 環(huán)境變量 Custom Log Formats SSLCACertificateFile SSLCACertificatePath SSLCADNRequestFile SSLCADNRequestPath SSLCARevocationFile SSLCARevocationPath SSLCertificateChainFile SSLCertificateFile SSLCertificateKeyFile SSLCipherSuite SSLCryptoDevice SSLEngine SSLHonorCipherOrder SSLMutex SSLOptions SSLPassPhraseDialog SSLProtocol SSLProxyCACertificateFile SSLProxyCACertificatePath SSLProxyCARevocationFile SSLProxyCARevocationPath SSLProxyCipherSuite SSLProxyEngine SSLProxyMachineCertificateFile SSLProxyMachineCertificatePath SSLProxyProtocol SSLProxyVerify SSLProxyVerifyDepth SSLRandomSeed SSLRequire SSLRequireSSL SSLSessionCache SSLSessionCacheTimeout SSLUserName SSLVerifyClient SSLVerifyDepth Apache Module mod_status Enabling Status Support 自動更新 Machine Readable Status File ExtendedStatus Apache Module mod_suexec SuexecUserGroup Apache Module mod_unique_id Theory Apache Module mod_userdir UserDir Apache Module mod_usertrack Logging 2-digit or 4-digit dates for cookies? CookieDomain CookieExpires CookieName CookieStyle CookieTracking Apache Module mod_version <IfVersion> Apache Module mod_vhost_alias 目錄名稱的轉(zhuǎn)換 示例 VirtualDocumentRoot VirtualDocumentRootIP VirtualScriptAlias VirtualScriptAliasIP 開發(fā)者文檔 Overview Topics External Resources Apache API notes Basic concepts How handlers work Resource allocation and resource pools Configuration Debugging Memory Allocation in APR Available debugging options Allowable Combinations Activating Debugging Options Documenting Apache 2.0 Apache 2.0 Hook Functions Creating a hook function Hooking the hook Converting Modules from Apache 1.3 to Apache 2.0 The easier changes ... The messier changes... Request Processing in Apache 2.0 The Request Processing Cycle The Request Parsing Phase The Security Phase The Preparation Phase The Handler Phase How Filters Work in Apache 2.0 Filter Types How are filters inserted? Asis Explanations 詞匯和索引 詞匯表 模塊索引 指令索引 指令速查 譯者聲明
Figuren

虛擬主機示例

本文檔試圖解釋一些在設(shè)置虛擬主機時經(jīng)常問及的問題。這些示例向你展示了如何在一個服務(wù)器上通過基于域名的或是基于IP的虛擬主機來部署多個web站點。另一份關(guān)于如何在一個代理服務(wù)器后構(gòu)建基于多個服務(wù)器的站點的說明文檔也很快就會出來。

在一個IP地址上運行多個基于域名的web站點

您的服務(wù)器有只一個IP地址,而在DNS中有很多域名(CNAMES)映射到這個機器。您而您想要在這個機器上運行www.example.comwww.example.org兩個站點。

注意

在您的Apache服務(wù)器配置中創(chuàng)建一個虛擬主機并不會自動在您的DNS中對主機名做相應(yīng)更新。您必須自己在DNS中添加域名來指向您的IP地址。否則別人是無法看到您的web站點的。您可以在您的hosts文件中添加這一條目來進行測試,但這種方法僅適用于那些有這些hosts文件的機器來使用。

服務(wù)器配置

# 確保Apache在監(jiān)聽80端口
Listen 80

# 為虛擬主機在所有IP地址上監(jiān)聽
NameVirtualHost *:80

<VirtualHost *:80>
DocumentRoot /www/example1
ServerName www.example.com

# 你可以在這里添加其他指令

</VirtualHost>

<VirtualHost *:80>
DocumentRoot /www/example2
ServerName www.example.org

# 你可以在這里添加其他指令

</VirtualHost>

因為星號匹配所有IP地址,所以主服務(wù)器不接收任何請求。因為www.example.com首先出現(xiàn)在配置文件中,所以它擁有最高優(yōu)先級,可以認為是默認服務(wù)器。這意味著如果一個請求不能與某個ServerName指令相匹配,它將會由第一個<VirtualHost>段所伺服。

注意

如果您愿意,您可以用確定的IP地址來取代"*"。在這種情況下,VirtualHost的參數(shù)必須NameVirtualHost的參數(shù)相符:

NameVirtualHost 172.20.30.40

<VirtualHost 172.20.30.40>
# 其他 ...

然而,當(dāng)您的IP地址無法確定的時候,使用"*"是很方便的,比如說,您的ISP給您配置的是動態(tài)IP地址,而您又使用了某種動態(tài)域名解析系統(tǒng)時。因為"*"匹配任何IP地址,所以在這種情況下,不論IP地址如何變化,您都不需要另外進行配置。

上述配置就是您在絕大多數(shù)情況下使用基于域名的虛擬主機時將要用到的。事實上,僅在一種情況下這樣的配置不會讓您滿意:您想為不同的IP地址或是端口提供不同的內(nèi)容。

在多于一個IP的情況下使用基于域名的虛擬主機。

注意

在這里討論的任何技術(shù)都可以推廣到使用任意數(shù)量的IP地址。

服務(wù)器有兩個IP地址。一個(172.20.30.40)用于主服務(wù)器server.domain.com ,另外一個(172.20.30.50)用于構(gòu)建兩個或多個虛擬主機。

服務(wù)器配置

Listen 80

# "主"服務(wù)器運行于:172.20.30.40
ServerName server.domain.com
DocumentRoot /www/mainserver

# 這是另外一個IP地址
NameVirtualHost 172.20.30.50

<VirtualHost 172.20.30.50>
DocumentRoot /www/example1
ServerName www.example.com

# 你可以在這里添加其他指令 ...

</VirtualHost>

<VirtualHost 172.20.30.50>
DocumentRoot /www/example2
ServerName www.example.org

# 你可以在這里添加其他指令 ...

</VirtualHost>

任何不是針對172.20.30.50的請求都將由主服務(wù)器來伺服。而提交給172.20.30.50卻沒有主機名或沒有"Host:"頭的請求,都將由www.example.com伺服。

在不同的IP的地址(比如一個內(nèi)部和一個外部地址)上提供相同的內(nèi)容

服務(wù)器有兩個IP地址(192.168.1.1172.20.30.40)。這個機器位于內(nèi)部(局域網(wǎng))網(wǎng)絡(luò)和外部(廣域網(wǎng))之間。在外部,域名server.example.com指向外部地址(172.20.30.40),而在內(nèi)部則指向內(nèi)部地址(192.168.1.1)。

服務(wù)器可以為來自內(nèi)部和外部的請求提供同樣的內(nèi)容,您只需要一個<VirtualHost>配置段就可以了。

服務(wù)器配置

NameVirtualHost 192.168.1.1
NameVirtualHost 172.20.30.40

<VirtualHost 192.168.1.1 172.20.30.40>
DocumentRoot /www/server1
ServerName server.example.com
ServerAlias server
</VirtualHost>

現(xiàn)在,從不同的網(wǎng)絡(luò)提交的請求都會由同一個<VirtualHost>段來伺服。

注意

在內(nèi)網(wǎng)中,您可以使用server這個名字來代替server.example.com這個全名。

跟上面一樣,在上述的例子里,您可以用"*"來代替具體的IP地址,這樣就可以對所有的地址都返回相同的內(nèi)容了。

在不同的端口上運行不同的站點

如果您想讓同一個IP的不同端口伺服多個域名。您可以借助在NameVirtualHost指令中定義端口的方法來達到這個目的。如果您想使用不帶"name:port"的<VirtualHost name:port>或是直接用Listen指令,您的配置將無法生效。

服務(wù)器配置

Listen 80
Listen 8080

NameVirtualHost 172.20.30.40:80
NameVirtualHost 172.20.30.40:8080

<VirtualHost 172.20.30.40:80>
ServerName www.example.com
DocumentRoot /www/domain-80
</VirtualHost>

<VirtualHost 172.20.30.40:8080>
ServerName www.example.com
DocumentRoot /www/domain-8080
</VirtualHost>

<VirtualHost 172.20.30.40:80>
ServerName www.example.org
DocumentRoot /www/otherdomain-80
</VirtualHost>

<VirtualHost 172.20.30.40:8080>
ServerName www.example.org
DocumentRoot /www/otherdomain-8080
</VirtualHost>

建立基于IP的虛擬主機

一個有兩個IP地址(172.20.30.40172.20.30.50)分別對應(yīng)域名www.example.comwww.example.org的配置如下:

服務(wù)器配置

Listen 80

<VirtualHost 172.20.30.40>
DocumentRoot /www/example1
ServerName www.example.com
</VirtualHost>

<VirtualHost 172.20.30.50>
DocumentRoot /www/example2
ServerName www.example.org
</VirtualHost>

如果存在主服務(wù)器,那么對沒有出現(xiàn)在任一個<VirtualHost>段中的請求(比如,對localhost的請求)都會由主服務(wù)器來伺服。

混用基于端口和基于IP的虛擬主機

如果您的服務(wù)器有兩個IP地址(172.20.30.40172.20.30.50)分別對應(yīng)域名www.example.comwww.example.org 。對每個域名,您都希望在80端口和8080端口發(fā)布您的網(wǎng)站。您可以這樣配置:

服務(wù)器配置

Listen 172.20.30.40:80
Listen 172.20.30.40:8080
Listen 172.20.30.50:80
Listen 172.20.30.50:8080

<VirtualHost 172.20.30.40:80>
DocumentRoot /www/example1-80
ServerName www.example.com
</VirtualHost>

<VirtualHost 172.20.30.40:8080>
DocumentRoot /www/example1-8080
ServerName www.example.com
</VirtualHost>

<VirtualHost 172.20.30.50:80>
DocumentRoot /www/example2-80
ServerName www.example.org
</VirtualHost>

<VirtualHost 172.20.30.50:8080>
DocumentRoot /www/example2-8080
ServerName www.example.org
</VirtualHost>

混用基于域名和基于IP的虛擬主機

您想在一些地址上配置基于域名的虛擬主機而在另外一些地址上配置基于IP的虛擬主機。

服務(wù)器配置

Listen 80

NameVirtualHost 172.20.30.40

<VirtualHost 172.20.30.40>
DocumentRoot /www/example1
ServerName www.example.com
</VirtualHost>

<VirtualHost 172.20.30.40>
DocumentRoot /www/example2
ServerName www.example.org
</VirtualHost>

<VirtualHost 172.20.30.40>
DocumentRoot /www/example3
ServerName www.example3.net
</VirtualHost>

# IP-based
<VirtualHost 172.20.30.50>
DocumentRoot /www/example4
ServerName www.example4.edu
</VirtualHost>

<VirtualHost 172.20.30.60>
DocumentRoot /www/example5
ServerName www.example5.gov
</VirtualHost>

<Virtual_host>mod_proxy模塊一起使用

下面的例子允許一個前端機器代理一個運行在其他機器上的虛擬主機。在如下示例中,在192.168.111.2機器上配置了一個同名的虛擬主機。這樣,萬一在同一臺機器上代理了多個主機名,ProxyPreserveHost On 指令能確保指定的主機名順利通過代理。

<VirtualHost *:*>
ProxyPreserveHost On
ProxyPass / http://192.168.111.2
ProxyPassReverse / http://192.168.111.2/
ServerName hostname.example.com
</VirtualHost>

使用"_default_"虛擬主機

為所有端口配置"_default_"虛擬主機

這樣配置可以捕獲所有指向沒指定的IP地址和端口的請求。比如:一個沒被任何虛擬主機使用的地址/端口對。

服務(wù)器配置

<VirtualHost _default_:*>
DocumentRoot /www/default
</VirtualHost>

這樣一個使用通配符端口的默認虛擬主機可以有效的防止請求被主服務(wù)器接收。

如果一個地址/端口對已經(jīng)被一個基于域名的虛擬主機使用,那么"_default_"虛擬主機決不會處理發(fā)向這個地址/端口對的請求。如果一個"Host:"請求頭中包含未知信息,或者干脆就沒有,那么它會被第一個基于域名的虛擬主機(也就是在配置文件中最先出現(xiàn)的使用了那個地址/端口對的虛擬主機)處理。

您可以用AliasMatchRewriteRule來重寫任何請求,使它指向一個簡單信息頁面(或腳本)。

為不同的端口配置"_default_"虛擬主機

與第一種一樣,但我們想讓服務(wù)器偵聽很多端口而第二個"_default_"虛擬主機單獨偵聽80端口。

服務(wù)器配置

<VirtualHost _default_:80>
DocumentRoot /www/default80
# ...
</VirtualHost>

<VirtualHost _default_:*>
DocumentRoot /www/default
# ...
</VirtualHost>

偵聽80端口的"_default_"虛擬主機(必須出現(xiàn)在所有使用通配符端口的虛擬主機之前)會捕獲所有發(fā)向一個未指定的IP地址的請求。主服務(wù)器將不會用于伺服任何請求。

為單獨一個端口配置"_default_"虛擬主機

如果我們只想在80端口上建立唯一的一個"_default_"虛擬主機,我們應(yīng)該這樣配置:

服務(wù)器配置

<VirtualHost _default_:80>
DocumentRoot /www/default
...
</VirtualHost>

發(fā)向一個未指定地址的80端口的請求將會由這個虛擬主機伺服;而發(fā)向未設(shè)定地址的其他端口的請求則由主服務(wù)器伺服。

將一個基于域名的虛擬主機移植為一個基于IP的虛擬主機

如果一個具有www.example.org域名的虛擬主機(就是基于域名配置示例中的第二個)得到了自己的IP地址。為了避免一些域名服務(wù)器或代理服務(wù)器在移植期間仍對這個域名做老的解析,我們可以采用一種過渡方法:同時提供新舊兩個IP地址的解析。

達到這個目的很簡單。因為我們只要簡單的把新地址(172.20.30.50)加入VirtualHost指令就行了。

服務(wù)器配置

Listen 80
ServerName www.example.com
DocumentRoot /www/example1

NameVirtualHost 172.20.30.40

<VirtualHost 172.20.30.40 172.20.30.50>
DocumentRoot /www/example2
ServerName www.example.org
# ...
</VirtualHost>

<VirtualHost 172.20.30.40>
DocumentRoot /www/example3
ServerName www.example.net
ServerAlias *.example.net
# ...
</VirtualHost>

現(xiàn)在這個虛擬主機就可以用新地址(表現(xiàn)為一個基于IP的虛擬主機)和舊地址(表現(xiàn)為一個基于域名的虛擬主機)同時進行訪問了。

使用ServerPath指令

如果我們在同一個服務(wù)器上運行了兩個基于域名的虛擬主機。為了匹配正確的虛擬主機,客戶端必須發(fā)送正確的"Host:"頭。而舊的使用HTTP/1.0的客戶端無法發(fā)送這樣的頭,這樣Apache就無法辨別客戶端想要連接哪個虛擬主機(會用主虛擬主機來伺服這個請求)。為了盡量提供向下兼容性,我們可以提供一個主虛擬主機來返回一個頁面,在頁面中加入指向基于域名的虛擬主機的URL前綴的鏈接。

服務(wù)器配置

NameVirtualHost 172.20.30.40

<VirtualHost 172.20.30.40>
# 主虛擬主機
DocumentRoot /www/subdomain
RewriteEngine On
RewriteRule ^/.* /www/subdomain/index.html
# ...
</VirtualHost>

<VirtualHost 172.20.30.40>
DocumentRoot /www/subdomain/sub1
ServerName www.sub1.domain.tld
ServerPath /sub1/
RewriteEngine On
RewriteRule ^(/sub1/.*) /www/subdomain$1
# ...
</VirtualHost>

<VirtualHost 172.20.30.40>
DocumentRoot /www/subdomain/sub2
ServerName www.sub2.domain.tld
ServerPath /sub2/
RewriteEngine On
RewriteRule ^(/sub2/.*) /www/subdomain$1
# ...
</VirtualHost>

由于ServerPath指令的作用,發(fā)送到http://www.sub1.domain.tld/sub1/的請求總會被sub1-vhost所伺服。
如果客戶端發(fā)送了正確的"Host:"頭,發(fā)送到http://www.sub1.domain.tld/的請求只會被sub1-vhost所伺服。如果沒有發(fā)送"Host:"頭,客戶端將會得到從主虛擬主機發(fā)送的信息頁面。

請注意,這里還有一點小問題:如果客戶端沒有發(fā)送"Host:"頭,發(fā)送到http://www.sub2.domain.tld/sub1/的請求還是會被sub1-vhost所伺服。

RewriteRule指令用以確保正確發(fā)送了"Host:"頭的客戶端可以任意使用這兩種URL變量,比如說:使用或不使用URL前綴。

Vorheriger Artikel: N?chster Artikel: