目录 搜索
首页 版本说明 从1.3升级到2.0 编译时配置的改变 运行时配置的改变 杂项变化 第三方模块 从 2.0 升级到 2.2 编译时配置的改变 运行时配置的改变 杂项变化 第三方模块 Apache 2.1/2.2 版本的新特性 核心增强 模块增强 程序增强 针对模块开发者的变化 Apache 2.0 版本的新特性 核心的增强 模块的增强 Apache许可证 参考手册 编译与安装 针对心急者的概述 要求 下载 解压 配置源代码树 编译 安装 配置 测试 升级 启动 Apache是怎样启动的 启动时发生错误 随系统启动时启动 额外信息 停止与重新启动 简介 立即停止 优雅重启 立即重启 优雅停止 附录:信号和竞争条件 运行时配置指令 主配置文件 配置文件的语法 模块 指令的作用域 .htaccess文件 配置段 配置段(容器)的类型 文件系统和网络空间 虚拟主机 代理 允许使用哪些指令? 配置段的合并 内容缓冲 简介 缓冲概述 安全方面的考虑 文件句柄缓冲 内存缓冲 磁盘缓冲 服务器全局配置 服务器标识 文件定位 限制资源的使用 日志文件 安全警告 错误日志 访问日志 日志滚动 管道日志 虚拟主机 其他日志文件 从URL到文件系统的映射 相关模块和指令 DocumentRoot DocumentRoot以外的文件 用户目录 URL重定向 反向代理 重写引擎 File Not Found 安全方面的提示 保持不断更新和升级 ServerRoot目录的权限 服务器端包含 关于CGI 未指定为脚本的CGI 指定为脚本的CGI 其他动态内容的来源 系统设置的保护 默认配置下服务器文件的保护 观察日志文件 动态共享对象(DSO) 实现 用法概要 背景知识 优点和缺点 内容协商 关于内容协商 Apache中的内容协商 协商的方法 打乱品质值 透明内容协商的扩展 超链和名称转换说明 缓冲说明 更多信息 自定义错误响应 行为 配置 自定义错误响应与重定向 地址和端口绑定 概述 针对IPv6的特殊考虑 怎样与虚拟主机协同工作 多路处理模块(MPM) 简介 选择一个MPM 默认的MPM 环境变量 设置环境变量 使用环境变量 用于特殊目的的环境变量 示例 处理器的使用 什么是处理器? 例子 程序员注意事项 过滤器 Apache2中的过滤器 智能过虑 使用过滤器 CGI脚本的Suexec执行 开始之前 suEXEC的安全模型 配置和安装suEXEC 启用和禁用suEXEC 使用suEXEC 调试suEXEC 谨防Jabberwock:警告和举例 性能调整 硬件和操作系统 运行时的配置 编译时的配置 附录:踪迹的详细分析 URL重写指南 mod_rewrite简介 实践方案 URL的规划 内容的处理 对访问的限制 其他 虚拟主机文档 总述 虚拟主机支持 配置指令 基于主机名的虚拟主机 基于域名的虚拟主机和基于IP的虚拟主机比较 使用基于域名的虚拟主机 与旧版浏览器的兼容性 基于IP地址的虚拟主机 系统需求 如何配置Apache 设置多个守护进程 配置拥有多个虚拟主机的单一守护进程 动态配置大量虚拟主机 动机 概述 简单的动态虚拟主机 一个实际的个人主页系统 在同一个服务器上架设多个主机的虚拟系统 更为有效的基于IP地址的虚拟主机 使用老版本的Apache 使用mod_rewrite实现简单的动态虚拟主机 使用mod_rewrite的个人主页系统 使用独立的虚拟主机配置文件 虚拟主机的普通配置示例 在一个IP地址上运行多个基于域名的web站点 在多于一个IP的情况下使用基于域名的虚拟主机 在不同的IP的地址(比如一个内部和一个外部地址)上提供相同的内容 在不同的端口上运行不同的站点 建立基于IP的虚拟主机 混用基于端口和基于IP的虚拟主机 混用基于域名和基于IP的虚拟主机 将虚拟主机和代理模块一起使用 使用默认虚拟主机 将一个基于域名的虚拟主机移植为一个基于IP的虚拟主机 使用ServerPath指令 深入讨论虚拟主机的匹配 解析配置文件 虚拟主机匹配 小技巧 文件描述符限制 关于DNS和Apache 一个简单示例 拒绝服务 "主服务器"地址 避免这些问题的小技巧 附录:进一步的提示 常见问题 概述 SSL/TLS 加密 概述 文档 mod_ssl 绪论 密码技术 证书 安全套接字层(SSL) 参考 兼容性 配置指令 环境变量 自定义日志功能 如何... 加密方案和强制性高等级安全 客户认证和访问控制 常见问题解答 About The Module Installation Configuration Certificates The SSL Protocol mod_ssl Support 如何.../指南 概述 认证 相关模块和指令 简介 先决条件 启用认证 允许多人访问 可能存在的问题 其他认证方法 更多信息 CGI动态页面 简介 配置Apache以允许CGI 编写CGI程序 程序还是不能运行! 幕后是怎样操作的? CGI模块/库 更多信息 服务器端包含 简介 什么是SSI? 配置服务器以允许SSI 基本SSI指令 附加的例子 我还能设置其它什么? 执行命令 高级SSI技术 总结 .htaccess文件 .htaccess文件 工作原理和使用方法 (不)使用.htaccess文件的场合 指令的生效 认证举例 服务器端包含(SSI)举例 CGI举例 疑难解答 用户网站目录 用户网站目录 用UserDir设置文件路径 限定哪些用户可以使用此功能 启用对每个用户都有效的cgi目录 允许用户改变配置 对特定平台的说明 概述 Microsoft Windows 其他平台 在Microsoft Windows中使用Apache 对操作系统的要求 下载 Apache for Windows 安装 Apache for Windows 配置 Apache for Windows 以服务方式运行 Apache for Windows 作为控制台程序运行Apache 测试安装 编译Windows下的Apache 系统要求 命令行编译 Developer Studio集成开发环境的工作区编译 项目组件 在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 服务器与支持程序 概述 httpd 语法 选项 ab 语法 选项 Bugs apachectl 语法 选项 apxs 语法 选项 举例 configure 语法 选项 环境变量 dbmmanage 语法 选项 Bugs htcacheclean 语法 选项 返回值 htdbm 语法 选项 Bugs 返回值 举例 安全方面的考虑 限制 htdigest 语法 选项 htpasswd 语法 选项 返回值 举例 安全方面的考虑 限制 logresolve 语法 选项 rotatelogs 语法 选项 Portability suexec 语法 选项 其他程序 log_server_status split-logfile 杂项文档 概述 相关标准 HTTP推荐标准 HTML推荐标准 认证 语言/国家代码 Apache 模块 描述模块的术语 说明 状态 源代码文件 模块标识符 兼容性 描述指令的术语 说明 语法 默认值(Default) 作用域(Context) 覆盖项(Override) 状态 模块(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 环境变量 CGI 脚本的调试 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 配置举例 启用压缩 代理服务器 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 带多扩展名的文件 内容编码 字符集和语言 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 正向和反向代理 简单示例 控制对代理服务器的访问 缓慢启动 局域网代理 协议调整 请求体 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 特殊字符的引用 环境变量 实用方案 RewriteBase RewriteCond RewriteEngine RewriteLock RewriteLog RewriteLogLevel RewriteMap RewriteOptions RewriteRule Apache Module mod_setenvif BrowserMatch BrowserMatchNoCase SetEnvIf SetEnvIfNoCase Apache Module mod_so 为Windows创建可加载模块 LoadFile LoadModule Apache Module mod_speling CheckSpelling Apache Module mod_ssl 环境变量 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 目录名称的转换 示例 VirtualDocumentRoot VirtualDocumentRootIP VirtualScriptAlias VirtualScriptAliasIP 开发者文档 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 词汇和索引 词汇表 模块索引 指令索引 指令速查 译者声明
文字

Apache模块 mod_proxy

说明 提供HTTP/1.1的代理/网关功能支持
状态 扩展(E)
模块名 proxy_module
源文件 mod_proxy.c

概述

警告

在您没有对服务器采取安全措施之前,请不要用ProxyRequests启用代理。一个开放的代理服务器不仅对您的网络有威胁,对整个因特网来说也同样如此。

此模块实现了Apache的代理/网关。它实现了以下规范的代理:AJP13(Apache JServe Protocol v1.3), FTP, CONNECT(用于SSL), HTTP/0.9, HTTP/1.0, HTTP/1.1 。此模块经配置后可用上述或其它协议连接其它代理模块。

Apache的代理功能(除mod_proxy以外)被划分到了几个不同的模块中:mod_proxy_http, mod_proxy_ftp, mod_proxy_ajp, mod_proxy_balancer, mod_proxy_connect 。这样,如果想使用一个或多个代理功能,就必须将mod_proxy对应的模块同时加载到服务器中(静态连接或用LoadModule动态加载)。

另外,其它模块还提供了扩展特性。mod_cache及其相关模块提供了缓冲特性。mod_ssl提供的SSLProxy*系列指令可以使用SSL/TLS连接远程服务器。这些提供扩展特性的模块必须在被正确加载和配置以后才能提供这些扩展功能。

正向和反向代理

Apache可以被配置为正向(forward)反向(reverse)代理。

正向代理是一个位于客户端和原始服务器(origin server)之间的服务器,为了从原始服务器取得内容,客户端向代理发送一个请求并指定目标(原始服务器),然后代理向原始服务器转交请求并将获得的内容返回给客户端。客户端必须要进行一些特别的设置才能使用正向代理。

正向代理的典型用途是为在防火墙内的局域网客户端提供访问Internet的途径。正向代理还可以使用缓冲特性(由mod_cache提供)减少网络使用率。

使用ProxyRequests指令即可激活正向代理。因为正向代理允许客户端通过它访问任意网站并且隐藏客户端自身,因此你必须采取安全措施以确保仅为经过授权的客户端提供服务。

反向代理正好相反,对于客户端而言它就像是原始服务器,并且客户端不需要进行任何特别的设置。客户端向反向代理的名字空间(name-space)中的内容发送普通请求,接着反向代理将判断向何处(原始服务器)转交请求,并将获得的内容返回给客户端,就像这些内容原本就是它自己的一样。

反向代理的典型用途是将防火墙后面的服务器提供给Internet用户访问。反向代理还可以为后端的多台服务器提供负载平衡,或为后端较慢的服务器提供缓冲服务。另外,还可以启用高级URL策略和管理技术,从而使处于不同web服务器系统的web页面同时存在于同一个URL空间下。

可以使用ProxyPass指令激活反向代理(在RewriteRule指令中使用[P]标记也可以)。配置反向代理并不需要打开ProxyRequests指令。

简单示例

下面的例子仅仅是为了给你一个基本概念而帮助入门而已,请仔细阅读每个指令的文档。

另外,如果想使用缓冲特性,请查看mod_cache文档。

正向代理

ProxyRequests On
ProxyVia On

<Proxy *>
Order deny,allow
Deny from all
Allow from internal.example.com
</Proxy>

反向代理

ProxyRequests Off

<Proxy *>
Order deny,allow
Allow from all
</Proxy>

ProxyPass /foo http://foo.example.com/bar
ProxyPassReverse /foo http://foo.example.com/bar

控制对代理服务器的访问

您可以通过<Proxy>的阻止功能来控制谁能访问您的代理。示例如下:

<Proxy *>
Order Deny,Allow
Deny from all
Allow from 192.168.0
</Proxy>

要了解更多访问控制信息,请参见mod_authz_host文档。

使用正向代理时严格控制访问权限(使用ProxyRequests指令)是非常重要的。否则你的代理会被客户端利用来访问其它服务器并且隐藏客户端的真实身份。这不仅对您的网络有威胁,对整个因特网来说也同样如此。当使用反向代理(在"ProxyRequests Off"条件下使用ProxyPass指令)的时候访问控制要相对宽松,因为客户端只能连接你配置的特定主机。

缓慢启动

如果您使用了ProxyBlock指令,将会在启动时查找并缓存主机名的IP地址以备后继的匹配测试使用。这将会花费几秒或更长的时间,这主要取决于主机名查找的速度。

局域网代理

位于局域网内的Apache代理服务器需要经由公司的防火墙转发对外部的请求(使用ProxyRemote指令来配置)。但当它访问局域网内的资源时,它能越过防火墙直接访问目的主机。在访问一个属于局域网的服务器从而进行直接连接时,NoProxy指令就会很有用。

局域网内的用户习惯于不在他们的WWW请求中加入本地域的名称,于是会使用"http://somehost/"来取代http://somehost.example.com/ 。一些商业代理服务器会不管这些,只是采用本地域的配置来简单的伺服这个请求。当使用了ProxyDomain指令来为服务器配置了一个代理服务时,Apache会发出一个重定向应答,以使客户端请求到达正确的、能满足要求的服务器地址。因为这样一来,用户的书签文件就会随之包含完整的主机名,所以这是首选的方法。

协议调整

mod_proxy向一个没有正确实现持久连接(KeepAlive)或HTTP/1.1的原始服务器发送请求的时候,可以通过设置两个环境变量来发送不带持久连接(KeepAlive)的HTTP/1.0请求。这两个变量是通过SetEnv指令设置的。

以下是force-proxy-request-1.0proxy-nokeepalive的例子:

<Location /buggyappserver/>
ProxyPass http://buggyappserver:7001/foo/
SetEnv force-proxy-request-1.0 1
SetEnv proxy-nokeepalive 1
</Location>

请求体

一些请求方法(如POST)包含一个请求体。HTTP协议要求包含请求体的请求或者使用块传输编码(chunked transfer encoding)或者包含一个Content-Length请求头。当将这种请求传递给原始服务器的时候,mod_proxy_http会始终尝试使用Content-Length请求头。但如果原始请求使用的是块编码,那么块编码也同样可以用于上行请求。可以使用环境变量控制这种选择。设置proxy-sendcl可以确保始终发送Content-Length头以与上游服务器保持最大程度的兼容性,而设置proxy-sendchunked可以通过继续使用块编码以尽可能最小化资源占用率。

AllowCONNECT 指令

说明 通过代理允许CONNECT的端口号
语法 AllowCONNECT port [port] ...
默认值 AllowCONNECT 443 563
作用域 server config, virtual host
状态 扩展(E)
模块 mod_proxy

AllowCONNECT指令指定了此代理的CONNECT方法可以连接的端口号列表。当今的浏览器在进行https连接请求时使用这种方法,而代理默认会将其转为http

默认只启用了默认的https端口(443)和默认的snews端口(563)。使用AllowCONNECT指令可以覆盖默认设置而改为仅允许连接列出的端口。

注意,必须确保mod_proxy_connect也同时存在于服务器中,这样才能支持CONNECT

NoProxy 指令

说明 直接进行连接的主机/域/网络
语法 NoProxy host [host] ...
作用域 server config, virtual host
状态 扩展(E)
模块 mod_proxy

此指令仅适用于局域网内的Apache代理服务器。NoProxy指令指定了一个中间以空格分隔的子网、IP地址、主机和/或域的列表。对某个匹配上述一个或多个列表项的主机的请求将直接被其伺服而不会转交到配置好的ProxyRemote代理服务器。

示例

ProxyRemote * http://firewall.mycompany.com:81
NoProxy .mycompany.com 192.168.112.0/21

NoProxy指令的host参数可以是以下选项之一:

是一个DNS域名的一部分,并在前面加上点号。它表示一批逻辑上属于同一个DNS区域的主机,也就是所有这些主机名具有相同的后缀,而这个"后缀"就是

例子

.com
.apache.org.

主机名(一个DNS域甚至也可能有一条DNS"A记录"!)的不同之处在于始终有一个前导点。

注意

域名不区分大小写并且始终认为是锚定在DNS树根上的,因此.MyDomain.com.mydomain.com.(注意结尾点号)是完全等同的。因为域的比较不需要进行DNS查询,因此它比子网比较更加高效。

子网

子网以点分十进制形式表示了一个因特网地址的一部分,有时会跟着一个斜杠和子网掩码,以指定子网中的有效bit位。它用于表示主机通过自身的普通网络接口可以访问的子网范围。未指定子网掩码的时候就假定忽略掉的(或为零的)结尾数字就是掩码,在这种情况下,掩码bit长度必须是8bit的整数倍。例如:

192.168192.168.0.0
子网"192.168.0.0"表示掩码为16bit(有时也用255.255.0.0表示)。
192.168.112.0/21
子网"192.168.112.0/21"表示掩码为21bit(有时也用255.255.248.0表示)。

在退化到极限的情况下,一个掩码为32bit的子网就等价于一个IP地址。而零个合法bit的子网("0.0.0.0/0")等价于常量"_Default_",可以匹配任何IP地址。

IP地址

IP地址以点分十进制形式表示了一个完整的因特网地址。一般来说,此地址代表一个主机,但并不需要一个DNS域名与这个地址对应。

示例

192.168.123.7

注意

一个IP地址不需要为一个DNS系统所解析,所以它能使apache获取更高性能。

主机名

主机名是一个完整的DNS域名,可以通过DNS域名服务解析为一个或多个IP地址。它代表了一个逻辑主机(与相反)而且必须解析成至少一个IP地址(或经常解析成具有不同IP地址的主机列表)。

例子

prep.ai.mit.edu
www.apache.org

注意

在很多情况下,指定一个IP地址代替主机名会更有效率。因为可以避免一次DNS查询。当使用一个低速的PPP与域名服务器连接时,Apache的域名解析会花费相当可观的时间。

主机名不区分大小写并且始终认为是锚定在DNS树根上的,因此WWW.MyDomain.comwww.mydomain.com.(注意结尾点号)是完全等同的。

参见

  • DNS相关问题

<Proxy> 指令

说明 应用于所代理资源的容器
语法 <Proxy wildcard-url> ...</Proxy>
作用域 server config, virtual host
状态 扩展(E)
模块 mod_proxy

位于<Proxy>配置段中的指令仅作用于匹配的代理内容。语句中可以使用shell风格的通配符。

比如说:下例仅允许yournetwork.example.com中的主机通过您的代理服务器访问代理内容:

<Proxy *>
Order Deny,Allow
Deny from all
Allow from yournetwork.example.com
</Proxy>

下例将在所有example.comfoo目录下的文件通过代理服务器发送之前用INCLUDES过滤器进行处理:

<Proxy http://example.com/foo/*>
SetOutputFilter INCLUDES
</Proxy>

ProxyBadHeader 指令

说明 确定如何处理不合法的应答头
语法 ProxyBadHeader IsError|Ignore|StartBody
默认值 ProxyBadHeader IsError
作用域 server config, virtual host
状态 扩展(E)
模块 mod_proxy
兼容性 仅在 Apache 2.0.44 及以后的版本中可用

ProxyBadHeader指令决定mod_proxy如何处理不合法的应答头(比如丢失冒号(:))。参数的取值范围如下:

IsError
以"502"(Bad Gateway)应答中止请求。这是默认行为。
Ignore
忽略,就像它们不存在一样。
StartBody
在接收到第一个非法头行时停止读取头,并将剩余部分当作应答体。这样做有助于和一个不规范的、经常忘记在应答头和应答体之间插入空行的后端服务器协同工作。

ProxyBlock 指令

说明 设置被代理屏蔽的语句、主机、域
语法 ProxyBlock *|word|host|domain [word|host|domain] ...
作用域 server config, virtual host
状态 扩展(E)
模块 mod_proxy

ProxyBlock指令指定了一个由空格分隔的语句、主机和/或域的列表。对所有匹配这些语句、主机和/或域的HTTP、HTTPS、FTP文档的请求都将被代理服务器阻断。代理模块亦会在启动时尝试确定列表中可能是主机名的项目对应的IP地址,并将其缓冲用于匹配测试。比如说:

示例

ProxyBlock joes-garage.com some-host.co.uk rocky.wotsamattau.edu

通过IP地址,rocky.wotsamattau.edu将可能同样被匹配。

请注意,wotsamattau已经足够匹配wotsamattau.edu了。

请注意

ProxyBlock *

将屏蔽对所有站点的连接。

ProxyDomain 指令

说明 代理请求的默认域名
语法 ProxyDomain Domain
作用域 server config, virtual host
状态 扩展(E)
模块 mod_proxy

此指令仅对位于局域网内的Apache代理服务器有用。ProxyDomain指令指定了apache代理服务器归属的默认域。如果遇到了一个对没有域名的主机的请求,就会根据配置自动生成一个加上了Domain的重定向应答。

示例

ProxyRemote * http://firewall.mycompany.com:81
NoProxy .mycompany.com 192.168.112.0/21
ProxyDomain .mycompany.com

ProxyErrorOverride 指令

说明 覆盖代理内容的错误页
语法 ProxyErrorOverride On|Off
默认值 ProxyErrorOverride Off
作用域 server config, virtual host
状态 扩展(E)
模块 mod_proxy
兼容性 仅在 Apache 2.0 及以后的版本中可用

此指令用于反向代理设置中您想为最终用户提供观感一致的错误页面时。它也同样允许包含文件(通过mod_include的SSI)获取错误号并作出相应的动作。(默认行为是显示被代理的服务器的错误页面,将此项目设为"On"将显示SSI错误信息。)

ProxyIOBufferSize 指令

说明 内部缓冲区大小
语法 ProxyIOBufferSize bytes
默认值 ProxyIOBufferSize 8192
作用域 server config, virtual host
状态 扩展(E)
模块 mod_proxy

ProxyIOBufferSize指令用于调整内部缓冲区(作为输入输出数据的暂存器)的大小。取值必须小于等于8192

在绝大多数情况下,不需要调整这个设置。

<ProxyMatch> 指令

说明 应用于匹配正则表达式的代理资源的容器
语法 <ProxyMatch regex> ...</ProxyMatch>
作用域 server config, virtual host
状态 扩展(E)
模块 mod_proxy

<ProxyMatch><Proxy>指令基本相同,只是匹配字符串可以为正则表达式。

ProxyMaxForwards 指令

说明 转发请求的最大代理数目
语法 ProxyMaxForwards number
默认值 ProxyMaxForwards 10
作用域 server config, virtual host
状态 扩展(E)
模块 mod_proxy
兼容性 仅在 Apache 2.0 及以后的版本中可用

ProxyMaxForwards指令指定了允许转发请求的最大代理数目。这个设置是为了避免无限代理循环或DoS攻击的发生。

示例

ProxyMaxForwards 15

ProxyPass 指令

说明 将一个远端服务器映射到本地服务器的URL空间中
语法 ProxyPass [path] !|url [key=value key=value ...]]
作用域 server config, virtual host, directory
状态 扩展(E)
模块 mod_proxy

该指令允许你将一个远端服务器映射到本地服务器的URL空间中,此时本地服务器并不充当代理角色,而是充当远程服务器的一个镜像。path是一个本地虚拟路径名,url是一个指向远程服务器的部分URL,并且不允许包含查询字符串。

当使用ProxyPass指令时,ProxyRequests指令通常应当被设为 off

假设本地服务器地址是:http://example.com/ ,那么,

ProxyPass /mirror/foo/ http://backend.example.com/

将会导致对http://example.com/mirror/foo/bar的本地请求将会在内部转换为一个代理请求:http://backend.example.com/bar

"!"指令对于您不想对某个子目录进行反向代理时很有用。比如说:

ProxyPass /mirror/foo/i !
ProxyPass /mirror/foo http://backend.example.com

将会代理除/mirror/foo/i之外的所有对backend.example.com/mirror/foo的请求。

注意

顺序很重要,您需要把拒绝指令放置在普通ProxyPass指令之前

As of Apache 2.1, the ability to use pooled connections to a backend server is available. Using the key=value parameters it is possible to tune this connection pooling. The default for a Hard Maximum for the number of connections is the number of threads per process in the active MPM. In the Prefork MPM, this is always 1, while with the Worker MPM it is controlled by the ThreadsPerChild.

Setting min will determine how many connections will always be open to the backend server. Upto the Soft Maximum or smax number of connections will be created on demand. Any connections above smax are subject to a time to live or ttl. Apache will never create more than the Hard Maximum or max connections to the backend server.

ProxyPass /example http://backend.example.com smax=5 max=20 ttl=120 retry=300

Parameter Default Description
min 0 Minumum number of connections that will always be open to the backend server.
max 1...n Hard Maximum number of connections that will be allowed to the backend server. The default for a Hard Maximum for the number of connections is the number of threads per process in the active MPM. In the Prefork MPM, this is always 1, while with the Worker MPM it is controlled by the ThreadsPerChild. Apache will never create more than the Hard Maximum connections to the backend server.
smax max Upto the Soft Maximum number of connections will be created on demand. Any connections above smax are subject to a time to live or ttl.
ttl - Time To Live for the inactive connections above the smax connections in seconds. Apache will close all connections that has not been used inside that time period.
timeout Timeout Connection timeout in seconds. If not set the Apache will wait until the free connection is available. This directive is used for limiting the number of connections to the backend server together with max parameter.
acquire - If set this will be the maximum time to wait for a free connection in the connection pool. If there are no free connections in the pool the Apache will return SERVER_BUSY status to the client.
keepalive Off This parameter should be used when you have a firewall between your Apache and the backend server, who tend to drop inactive connections. This flag will tell the Operating System to send KEEP_ALIVE messages on inactive connections (interval depends on global OS settings, generally 120ms), and thus prevent the firewall to drop the connection. To enable keepalive set this property value to On.
retry 60 Connection pool worker retry timeout in seconds. If the connection pool worker to the backend server is in the error state, Apache will not forward any requests to that server until the timeout expires. This enables to shut down the backend server for maintenance, and bring it back online later.
loadfactor 1 Worker load factor. Used with BalancerMember. It is a number between 1 and 100 and defines the normalized weighted load applied to the worker.
route - Route of the worker when used inside load balancer. The route is a value appended to seesion id.
redirect - Redirection Route of the worker. This value is usually set dynamically to enable safe removal of the node from the cluster. If set all requests without session id will be redirected to the BalancerMember that has route parametar equal as this value.

If the Proxy directive scheme starts with the balancer:// then a virtual worker that does not really communicate with the backend server will be created. Instead it is responsible for the management of several "real" workers. In that case the special set of parameters can be add to this virtual worker.

Parameter Default Description
lbmethod - Balancer load-balance method. Select the load-balancing scheduler method to use. Either byrequests, to perform weighted request counting or bytraffic, to perform weighted traffic byte count balancing. Default is byrequests.
stickysession - Balancer sticky session name. The value is usually set to something like JSESSIONIDPHPSESSIONID, and it depends on the backend application server that support sessions.
nofailover Off If set to On the session will break if the worker is in error state or disabled. Set this value to On if backend servers do not support session replication.
timeout 0 Balancer timeout in seconds. If set this will be the maximum time to wait for a free worker. Default is not to wait.
maxattempts 1 Maximum number of failover attempts before giving up.

ProxyPass /special-area http://special.example.com/ smax=5 max=10
ProxyPass / balancer://mycluster stickysession=jsessionid nofailover=On
<Proxy balancer://mycluster>
BalancerMember http://1.2.3.4:8009
BalancerMember http://1.2.3.5:8009 smax=10
# Less powerful server, don't send as many requests there
BalancerMember http://1.2.3.6:8009 smax=1 loadfactor=20
</Proxy>

When used inside a <Location> section, the first argument is omitted and the local directory is obtained from the <Location>.

If you require a more flexible reverse-proxy configuration, see the RewriteRule directive with the [P] flag.

ProxyPassReverse 指令

说明 调整由反向代理服务器发送的HTTP应答头中的URL
语法 ProxyPassReverse [path] url
作用域 server config, virtual host, directory
状态 扩展(E)
模块 mod_proxy

此指令使Apache调整HTTP重定向应答中Location, Content-Location, URI头里的URL。这样可以避免在Apache作为反向代理使用时,后端服务器的HTTP重定向造成的绕过反向代理的问题。

只有明确指定的应答头会被重写,其它应答头保持不变,并且HTML页面中的URL也不会被修改。如果被代理的内容包含绝对URL引用,那么将会绕过代理。有一个第三方模块可以检查并改写HTML中的URL引用,该模块就是Nick Kew编写的mod_proxy_html。

path是本地虚拟路径的名称。url是远端服务器的部分URL。与ProxyPass指令中的使用方法相同。

例如,假定本地服务器拥有地址http://example.com/ ,那么

ProxyPass /mirror/foo/ http://backend.example.com/
ProxyPassReverse /mirror/foo/ http://backend.example.com/
ProxyPassReverseCookieDomain backend.example.com public.example.com
ProxyPassReverseCookiePath / /mirror/foo/

不仅会把所有对http://example.com/mirror/foo/bar的请求直接转换为对http://backend.example.com/bar的代理请求(由ProxyPass提供的功能),它还会重定向服务器backend.example.com的发送:当http://backend.example.com/bar被它重定向到http://backend.example.com/quux时,Apache会在转交HTTP重定向应答到客户端之前调整它为http://example.com/mirror/foo/quux 。注意:被用于构建URL的主机名与UseCanonicalName指令的设置有关。

注意,此ProxyPassReverse指令亦可与mod_rewrite的代理穿透特性(RewriteRule ... [P])联用。因为它不依赖于相应的ProxyPass指令。

当在<Location>配置段中使用时,第一个参数会被忽略而采用由<Location>指令指定的本地目录。

ProxyPassReverseCookieDomain 指令

说明 Adjusts the Domain string in Set-Cookie headers from a reverse- proxied server
语法 ProxyPassReverseCookieDomain internal-domain public-domain
作用域 server config, virtual host, directory
状态 扩展(E)
模块 mod_proxy

Usage is basically similar to ProxyPassReverse, but instead of rewriting headers that are a URL, this rewrites the domain string in Set-Cookie headers.

ProxyPassReverseCookiePath 指令

说明 Adjusts the Path string in Set-Cookie headers from a reverse- proxied server
语法 ProxyPassReverseCookiePath internal-path public-path
作用域 server config, virtual host, directory
状态 扩展(E)
模块 mod_proxy

Usage is basically similar to ProxyPassReverse, but instead of rewriting headers that are a URL, this rewrites the path string in Set-Cookie headers.

ProxyPreserveHost 指令

说明 使用进入的HTTP请求头来发送代理请求
语法 ProxyPreserveHost On|Off
默认值 ProxyPreserveHost Off
作用域 server config, virtual host
状态 扩展(E)
模块 mod_proxy
兼容性 仅在 Apache 2.0.31 及以后的版本中可用

当启用时,此选项将把传入请求的"Host:"行传递给被代理的主机,而不是传递在ProxyPass中指定的主机名。

此选项一般为Off状态。It is mostly useful in special configurations like proxied mass name-based virtual hosting, where the original Host header needs to be evaluated by the backend server.

ProxyReceiveBufferSize 指令

说明 代理HTTP和FTP连接的接收缓冲区大小(字节)
语法 ProxyReceiveBufferSize bytes
默认值 ProxyReceiveBufferSize 0
作用域 server config, virtual host
状态 扩展(E)
模块 mod_proxy

ProxyReceiveBufferSize指令为增加的吞吐量指定了代理HTTP和FTP连接的(TCP/IP)网络接收缓冲区。这个值必须大于512 ,或设置为"0"表示使用系统默认的缓冲大小。

示例

ProxyReceiveBufferSize 2048

ProxyRemote 指令

说明 用于处理某些特定请求的远端代理
语法 ProxyRemote match remote-server
作用域 server config, virtual host
状态 扩展(E)
模块 mod_proxy

此指令定义了此代理的远端代理。match可以是远端服务器支持的URL形式的名称、或是远端服务器使用的部分URL、或是代表服务器可以接受所有请求的"*"。remote-server是远端服务器的部分URL。语法为:

remote-server = scheme://hostname[:port]

scheme是与远端服务器交换信息时使用的协议;本模块暂时只支持http协议。

示例

ProxyRemote http://goodguys.com/ http://mirrorguys.com:8000
ProxyRemote * http://cleversite.com
ProxyRemote ftp http://ftpproxy.mydomain.com:8080

在最后一个例子中,代理会将封装到另外一个HTTP代理请求中的FTP请求转交到另外一个能处理它们的代理去。

此选项也支持反向代理配置:一个后端web服务器可以被嵌入到一个虚拟主机的URL空间中,哪怕它是由另一个代理转交过来的。

ProxyRemoteMatch 指令

说明 处理匹配正则表达式的请求的远端代理
语法 ProxyRemoteMatch regex remote-server
作用域 server config, virtual host
状态 扩展(E)
模块 mod_proxy

ProxyRemoteMatchProxyRemote令基本相同。除了第一个参数是由一个请求的URL变成了匹配的正则表达式。

ProxyRequests 指令

说明 启用正向(标准)代理请求
语法 ProxyRequests On|Off
默认值 ProxyRequests Off
作用域 server config, virtual host
状态 扩展(E)
模块 mod_proxy

此指令将允许或禁止Apache作为正向代理服务器的功能(设置为Off并不会禁用ProxyPass指令)。

在一个典型的反向代理配置中,此可选项一般设置为Off

为了能够代理HTTP或FTP站点,mod_proxy_httpmod_proxy_ftp必须同时存在于服务器中。

警告

在您没有对服务器采取安全措施之前,请不要用ProxyRequests启用您的代理。一个开放的代理服务器不仅对您的网络有威胁,对整个因特网来说也同样如此。

ProxyTimeout 指令

说明 代理请求的网络超时
语法 ProxyTimeout seconds
默认值 ProxyTimeout 300
作用域 server config, virtual host
状态 扩展(E)
模块 mod_proxy
兼容性 仅在 Apache 2.0.31 及以后的版本中可用

此指令允许用户对代理请求指定一个超时值。当你有一个很慢/错误多多的应用服务器经常挂起,而您宁愿返回一个超时的失败信息也不愿意继续等待不知道多久的时候,这个功能是很有用的。

ProxyVia 指令

说明 控制代理对Via应答头的使用
语法 ProxyVia On|Off|Full|Block
默认值 ProxyVia Off
作用域 server config, virtual host
状态 扩展(E)
模块 mod_proxy

此指令控制代理对"Via:"头的使用。它的目的是控制位于代理服务器链中的代理请求的流向。参阅RFC 2616(HTTP/1.1)14.45小节以获得关于"Via:"头的解释。

  • 如果设置为默认值Off ,将不会采取特殊的处理。如果一个请求或应答包含"Via:"头,将不进行任何修改而直接通过。
  • 如果设置为On每个请求和应答都会对应当前主机得到一个"Via:"头。
  • 如果设置为Full ,每个产生的"Via:"头中都会额外加入Apache服务器的版本,以"Via:"注释域出现。
  • 如果设置为Block ,每个代理请求中的所有"Via:"头行都将被删除。且不会产生新的"Via:"头。
上一篇: 下一篇: