?
This document uses PHP Chinese website manual Release
說(shuō)明 | 提供HTTP/1.1的代理/網(wǎng)關(guān)功能支持 |
---|---|
狀態(tài) | 擴(kuò)展(E) |
模塊名 | proxy_module |
源文件 | mod_proxy.c |
在您沒(méi)有對(duì)服務(wù)器采取安全措施之前,請(qǐng)不要用ProxyRequests
啟用代理。一個(gè)開(kāi)放的代理服務(wù)器不僅對(duì)您的網(wǎng)絡(luò)有威脅,對(duì)整個(gè)因特網(wǎng)來(lái)說(shuō)也同樣如此。
此模塊實(shí)現(xiàn)了Apache的代理/網(wǎng)關(guān)。它實(shí)現(xiàn)了以下規(guī)范的代理:AJP13
(Apache JServe Protocol v1.3), FTP
, CONNECT
(用于SSL), HTTP/0.9
, HTTP/1.0
, HTTP/1.1
。此模塊經(jīng)配置后可用上述或其它協(xié)議連接其它代理模塊。
Apache的代理功能(除mod_proxy
以外)被劃分到了幾個(gè)不同的模塊中:mod_proxy_http
, mod_proxy_ftp
, mod_proxy_ajp
, mod_proxy_balancer
, mod_proxy_connect
。這樣,如果想使用一個(gè)或多個(gè)代理功能,就必須將mod_proxy
和對(duì)應(yīng)的模塊同時(shí)加載到服務(wù)器中(靜態(tài)連接或用LoadModule
動(dòng)態(tài)加載)。
另外,其它模塊還提供了擴(kuò)展特性。mod_cache
及其相關(guān)模塊提供了緩沖特性。mod_ssl
提供的SSLProxy*
系列指令可以使用SSL/TLS連接遠(yuǎn)程服務(wù)器。這些提供擴(kuò)展特性的模塊必須在被正確加載和配置以后才能提供這些擴(kuò)展功能。
Apache可以被配置為正向(forward)和反向(reverse)代理。
正向代理是一個(gè)位于客戶(hù)端和原始服務(wù)器(origin server)之間的服務(wù)器,為了從原始服務(wù)器取得內(nèi)容,客戶(hù)端向代理發(fā)送一個(gè)請(qǐng)求并指定目標(biāo)(原始服務(wù)器),然后代理向原始服務(wù)器轉(zhuǎn)交請(qǐng)求并將獲得的內(nèi)容返回給客戶(hù)端??蛻?hù)端必須要進(jìn)行一些特別的設(shè)置才能使用正向代理。
正向代理的典型用途是為在防火墻內(nèi)的局域網(wǎng)客戶(hù)端提供訪問(wèn)Internet的途徑。正向代理還可以使用緩沖特性(由mod_cache
提供)減少網(wǎng)絡(luò)使用率。
使用ProxyRequests
指令即可激活正向代理。因?yàn)檎虼碓试S客戶(hù)端通過(guò)它訪問(wèn)任意網(wǎng)站并且隱藏客戶(hù)端自身,因此你必須采取安全措施以確保僅為經(jīng)過(guò)授權(quán)的客戶(hù)端提供服務(wù)。
反向代理正好相反,對(duì)于客戶(hù)端而言它就像是原始服務(wù)器,并且客戶(hù)端不需要進(jìn)行任何特別的設(shè)置??蛻?hù)端向反向代理的名字空間(name-space)中的內(nèi)容發(fā)送普通請(qǐng)求,接著反向代理將判斷向何處(原始服務(wù)器)轉(zhuǎn)交請(qǐng)求,并將獲得的內(nèi)容返回給客戶(hù)端,就像這些內(nèi)容原本就是它自己的一樣。
反向代理的典型用途是將防火墻后面的服務(wù)器提供給Internet用戶(hù)訪問(wèn)。反向代理還可以為后端的多臺(tái)服務(wù)器提供負(fù)載平衡,或?yàn)楹蠖溯^慢的服務(wù)器提供緩沖服務(wù)。另外,還可以啟用高級(jí)URL策略和管理技術(shù),從而使處于不同web服務(wù)器系統(tǒng)的web頁(yè)面同時(shí)存在于同一個(gè)URL空間下。
可以使用ProxyPass
指令激活反向代理(在RewriteRule
指令中使用[P]
標(biāo)記也可以)。配置反向代理并不需要打開(kāi)ProxyRequests
指令。
下面的例子僅僅是為了給你一個(gè)基本概念而幫助入門(mén)而已,請(qǐng)仔細(xì)閱讀每個(gè)指令的文檔。
另外,如果想使用緩沖特性,請(qǐng)查看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
您可以通過(guò)<Proxy>
的阻止功能來(lái)控制誰(shuí)能訪問(wèn)您的代理。示例如下:
<Proxy *>
Order Deny,Allow
Deny from all
Allow from 192.168.0
</Proxy>
要了解更多訪問(wèn)控制信息,請(qǐng)參見(jiàn)mod_authz_host
文檔。
使用正向代理時(shí)嚴(yán)格控制訪問(wèn)權(quán)限(使用ProxyRequests
指令)是非常重要的。否則你的代理會(huì)被客戶(hù)端利用來(lái)訪問(wèn)其它服務(wù)器并且隱藏客戶(hù)端的真實(shí)身份。這不僅對(duì)您的網(wǎng)絡(luò)有威脅,對(duì)整個(gè)因特網(wǎng)來(lái)說(shuō)也同樣如此。當(dāng)使用反向代理(在"ProxyRequests Off
"條件下使用ProxyPass
指令)的時(shí)候訪問(wèn)控制要相對(duì)寬松,因?yàn)榭蛻?hù)端只能連接你配置的特定主機(jī)。
如果您使用了ProxyBlock
指令,將會(huì)在啟動(dòng)時(shí)查找并緩存主機(jī)名的IP地址以備后繼的匹配測(cè)試使用。這將會(huì)花費(fèi)幾秒或更長(zhǎng)的時(shí)間,這主要取決于主機(jī)名查找的速度。
位于局域網(wǎng)內(nèi)的Apache代理服務(wù)器需要經(jīng)由公司的防火墻轉(zhuǎn)發(fā)對(duì)外部的請(qǐng)求(使用ProxyRemote
指令來(lái)配置)。但當(dāng)它訪問(wèn)局域網(wǎng)內(nèi)的資源時(shí),它能越過(guò)防火墻直接訪問(wèn)目的主機(jī)。在訪問(wèn)一個(gè)屬于局域網(wǎng)的服務(wù)器從而進(jìn)行直接連接時(shí),NoProxy
指令就會(huì)很有用。
局域網(wǎng)內(nèi)的用戶(hù)習(xí)慣于不在他們的WWW請(qǐng)求中加入本地域的名稱(chēng),于是會(huì)使用"http://somehost/"來(lái)取代http://somehost.example.com/
。一些商業(yè)代理服務(wù)器會(huì)不管這些,只是采用本地域的配置來(lái)簡(jiǎn)單的伺服這個(gè)請(qǐng)求。當(dāng)使用了ProxyDomain
指令來(lái)為服務(wù)器配置了一個(gè)代理服務(wù)時(shí),Apache會(huì)發(fā)出一個(gè)重定向應(yīng)答,以使客戶(hù)端請(qǐng)求到達(dá)正確的、能滿(mǎn)足要求的服務(wù)器地址。因?yàn)檫@樣一來(lái),用戶(hù)的書(shū)簽文件就會(huì)隨之包含完整的主機(jī)名,所以這是首選的方法。
當(dāng)mod_proxy
向一個(gè)沒(méi)有正確實(shí)現(xiàn)持久連接(KeepAlive)或HTTP/1.1的原始服務(wù)器發(fā)送請(qǐng)求的時(shí)候,可以通過(guò)設(shè)置兩個(gè)環(huán)境變量來(lái)發(fā)送不帶持久連接(KeepAlive)的HTTP/1.0請(qǐng)求。這兩個(gè)變量是通過(guò)SetEnv
指令設(shè)置的。
以下是force-proxy-request-1.0
和proxy-nokeepalive
的例子:
<Location /buggyappserver/>
ProxyPass http://buggyappserver:7001/foo/
SetEnv force-proxy-request-1.0 1
SetEnv proxy-nokeepalive 1
</Location>
一些請(qǐng)求方法(如POST)包含一個(gè)請(qǐng)求體。HTTP協(xié)議要求包含請(qǐng)求體的請(qǐng)求或者使用塊傳輸編碼(chunked transfer encoding)或者包含一個(gè)Content-Length
請(qǐng)求頭。當(dāng)將這種請(qǐng)求傳遞給原始服務(wù)器的時(shí)候,mod_proxy_http
會(huì)始終嘗試使用Content-Length
請(qǐng)求頭。但如果原始請(qǐng)求使用的是塊編碼,那么塊編碼也同樣可以用于上行請(qǐng)求??梢允褂铆h(huán)境變量控制這種選擇。設(shè)置proxy-sendcl
可以確保始終發(fā)送Content-Length
頭以與上游服務(wù)器保持最大程度的兼容性,而設(shè)置proxy-sendchunked
可以通過(guò)繼續(xù)使用塊編碼以盡可能最小化資源占用率。
說(shuō)明 | 通過(guò)代理允許CONNECT 的端口號(hào) |
---|---|
語(yǔ)法 | AllowCONNECT port [port] ... |
默認(rèn)值 | AllowCONNECT 443 563 |
作用域 | server config, virtual host |
狀態(tài) | 擴(kuò)展(E) |
模塊 | mod_proxy |
AllowCONNECT
指令指定了此代理的CONNECT
方法可以連接的端口號(hào)列表。當(dāng)今的瀏覽器在進(jìn)行https
連接請(qǐng)求時(shí)使用這種方法,而代理默認(rèn)會(huì)將其轉(zhuǎn)為http
。
默認(rèn)只啟用了默認(rèn)的https端口(443
)和默認(rèn)的snews端口(563
)。使用AllowCONNECT
指令可以覆蓋默認(rèn)設(shè)置而改為僅允許連接列出的端口。
注意,必須確保mod_proxy_connect
也同時(shí)存在于服務(wù)器中,這樣才能支持CONNECT
。
說(shuō)明 | 直接進(jìn)行連接的主機(jī)/域/網(wǎng)絡(luò) |
---|---|
語(yǔ)法 | NoProxy host [host] ... |
作用域 | server config, virtual host |
狀態(tài) | 擴(kuò)展(E) |
模塊 | mod_proxy |
此指令僅適用于局域網(wǎng)內(nèi)的Apache代理服務(wù)器。NoProxy
指令指定了一個(gè)中間以空格分隔的子網(wǎng)、IP地址、主機(jī)和/或域的列表。對(duì)某個(gè)匹配上述一個(gè)或多個(gè)列表項(xiàng)的主機(jī)的請(qǐng)求將直接被其伺服而不會(huì)轉(zhuǎn)交到配置好的ProxyRemote
代理服務(wù)器。
ProxyRemote * http://firewall.mycompany.com:81
NoProxy .mycompany.com 192.168.112.0/21
NoProxy
指令的host參數(shù)可以是以下選項(xiàng)之一:
域是一個(gè)DNS域名的一部分,并在前面加上點(diǎn)號(hào)。它表示一批邏輯上屬于同一個(gè)DNS區(qū)域的主機(jī),也就是所有這些主機(jī)名具有相同的后綴,而這個(gè)"后綴"就是域。
.com
.apache.org.
域和主機(jī)名(一個(gè)DNS域甚至也可能有一條DNS"A記錄"!)的不同之處在于域始終有一個(gè)前導(dǎo)點(diǎn)。
域名不區(qū)分大小寫(xiě)并且始終認(rèn)為是錨定在DNS樹(shù)根上的,因此.MyDomain.com
和.mydomain.com.
(注意結(jié)尾點(diǎn)號(hào))是完全等同的。因?yàn)橛虻谋容^不需要進(jìn)行DNS查詢(xún),因此它比子網(wǎng)比較更加高效。
子網(wǎng)以點(diǎn)分十進(jìn)制形式表示了一個(gè)因特網(wǎng)地址的一部分,有時(shí)會(huì)跟著一個(gè)斜杠和子網(wǎng)掩碼,以指定子網(wǎng)中的有效bit位。它用于表示主機(jī)通過(guò)自身的普通網(wǎng)絡(luò)接口可以訪問(wèn)的子網(wǎng)范圍。未指定子網(wǎng)掩碼的時(shí)候就假定忽略掉的(或?yàn)榱愕?結(jié)尾數(shù)字就是掩碼,在這種情況下,掩碼bit長(zhǎng)度必須是8bit的整數(shù)倍。例如:
192.168
或192.168.0.0
192.168.0.0
"表示掩碼為16bit(有時(shí)也用255.255.0.0
表示)。192.168.112.0/21
192.168.112.0/21
"表示掩碼為21bit(有時(shí)也用255.255.248.0
表示)。在退化到極限的情況下,一個(gè)掩碼為32bit的子網(wǎng)就等價(jià)于一個(gè)IP地址。而零個(gè)合法bit的子網(wǎng)("0.0.0.0/0")等價(jià)于常量"_Default_",可以匹配任何IP地址。
IP地址以點(diǎn)分十進(jìn)制形式表示了一個(gè)完整的因特網(wǎng)地址。一般來(lái)說(shuō),此地址代表一個(gè)主機(jī),但并不需要一個(gè)DNS域名與這個(gè)地址對(duì)應(yīng)。
192.168.123.7
一個(gè)IP地址不需要為一個(gè)DNS系統(tǒng)所解析,所以它能使apache獲取更高性能。
主機(jī)名是一個(gè)完整的DNS域名,可以通過(guò)DNS域名服務(wù)解析為一個(gè)或多個(gè)IP地址。它代表了一個(gè)邏輯主機(jī)(與域相反)而且必須解析成至少一個(gè)IP地址(或經(jīng)常解析成具有不同IP地址的主機(jī)列表)。
prep.ai.mit.edu
www.apache.org
在很多情況下,指定一個(gè)IP地址代替主機(jī)名會(huì)更有效率。因?yàn)榭梢员苊庖淮蜠NS查詢(xún)。當(dāng)使用一個(gè)低速的PPP與域名服務(wù)器連接時(shí),Apache的域名解析會(huì)花費(fèi)相當(dāng)可觀的時(shí)間。
主機(jī)名不區(qū)分大小寫(xiě)并且始終認(rèn)為是錨定在DNS樹(shù)根上的,因此WWW.MyDomain.com
和www.mydomain.com.
(注意結(jié)尾點(diǎn)號(hào))是完全等同的。
說(shuō)明 | 應(yīng)用于所代理資源的容器 |
---|---|
語(yǔ)法 | <Proxy wildcard-url> ...</Proxy> |
作用域 | server config, virtual host |
狀態(tài) | 擴(kuò)展(E) |
模塊 | mod_proxy |
位于<Proxy>
配置段中的指令僅作用于匹配的代理內(nèi)容。語(yǔ)句中可以使用shell風(fēng)格的通配符。
比如說(shuō):下例僅允許yournetwork.example.com
中的主機(jī)通過(guò)您的代理服務(wù)器訪問(wèn)代理內(nèi)容:
<Proxy *>
Order Deny,Allow
Deny from all
Allow from yournetwork.example.com
</Proxy>
下例將在所有example.com
的foo
目錄下的文件通過(guò)代理服務(wù)器發(fā)送之前用INCLUDES
過(guò)濾器進(jìn)行處理:
<Proxy http://example.com/foo/*>
SetOutputFilter INCLUDES
</Proxy>
說(shuō)明 | 確定如何處理不合法的應(yīng)答頭 |
---|---|
語(yǔ)法 | ProxyBadHeader IsError|Ignore|StartBody |
默認(rèn)值 | ProxyBadHeader IsError |
作用域 | server config, virtual host |
狀態(tài) | 擴(kuò)展(E) |
模塊 | mod_proxy |
兼容性 | 僅在 Apache 2.0.44 及以后的版本中可用 |
ProxyBadHeader
指令決定mod_proxy
如何處理不合法的應(yīng)答頭(比如丟失冒號(hào)(:))。參數(shù)的取值范圍如下:
IsError
Ignore
StartBody
說(shuō)明 | 設(shè)置被代理屏蔽的語(yǔ)句、主機(jī)、域 |
---|---|
語(yǔ)法 | ProxyBlock *|word|host|domain [word|host|domain] ... |
作用域 | server config, virtual host |
狀態(tài) | 擴(kuò)展(E) |
模塊 | mod_proxy |
ProxyBlock
指令指定了一個(gè)由空格分隔的語(yǔ)句、主機(jī)和/或域的列表。對(duì)所有匹配這些語(yǔ)句、主機(jī)和/或域的HTTP、HTTPS、FTP文檔的請(qǐng)求都將被代理服務(wù)器阻斷。代理模塊亦會(huì)在啟動(dòng)時(shí)嘗試確定列表中可能是主機(jī)名的項(xiàng)目對(duì)應(yīng)的IP地址,并將其緩沖用于匹配測(cè)試。比如說(shuō):
ProxyBlock joes-garage.com some-host.co.uk rocky.wotsamattau.edu
通過(guò)IP地址,rocky.wotsamattau.edu
將可能同樣被匹配。
請(qǐng)注意,wotsamattau
已經(jīng)足夠匹配wotsamattau.edu
了。
請(qǐng)注意
ProxyBlock *
將屏蔽對(duì)所有站點(diǎn)的連接。
說(shuō)明 | 代理請(qǐng)求的默認(rèn)域名 |
---|---|
語(yǔ)法 | ProxyDomain Domain |
作用域 | server config, virtual host |
狀態(tài) | 擴(kuò)展(E) |
模塊 | mod_proxy |
此指令僅對(duì)位于局域網(wǎng)內(nèi)的Apache代理服務(wù)器有用。ProxyDomain
指令指定了apache代理服務(wù)器歸屬的默認(rèn)域。如果遇到了一個(gè)對(duì)沒(méi)有域名的主機(jī)的請(qǐng)求,就會(huì)根據(jù)配置自動(dòng)生成一個(gè)加上了Domain的重定向應(yīng)答。
ProxyRemote * http://firewall.mycompany.com:81
NoProxy .mycompany.com 192.168.112.0/21
ProxyDomain .mycompany.com
說(shuō)明 | 覆蓋代理內(nèi)容的錯(cuò)誤頁(yè) |
---|---|
語(yǔ)法 | ProxyErrorOverride On|Off |
默認(rèn)值 | ProxyErrorOverride Off |
作用域 | server config, virtual host |
狀態(tài) | 擴(kuò)展(E) |
模塊 | mod_proxy |
兼容性 | 僅在 Apache 2.0 及以后的版本中可用 |
此指令用于反向代理設(shè)置中您想為最終用戶(hù)提供觀感一致的錯(cuò)誤頁(yè)面時(shí)。它也同樣允許包含文件(通過(guò)mod_include
的SSI)獲取錯(cuò)誤號(hào)并作出相應(yīng)的動(dòng)作。(默認(rèn)行為是顯示被代理的服務(wù)器的錯(cuò)誤頁(yè)面,將此項(xiàng)目設(shè)為"On"將顯示SSI錯(cuò)誤信息。)
說(shuō)明 | 內(nèi)部緩沖區(qū)大小 |
---|---|
語(yǔ)法 | ProxyIOBufferSize bytes |
默認(rèn)值 | ProxyIOBufferSize 8192 |
作用域 | server config, virtual host |
狀態(tài) | 擴(kuò)展(E) |
模塊 | mod_proxy |
ProxyIOBufferSize
指令用于調(diào)整內(nèi)部緩沖區(qū)(作為輸入輸出數(shù)據(jù)的暫存器)的大小。取值必須小于等于8192
。
在絕大多數(shù)情況下,不需要調(diào)整這個(gè)設(shè)置。
說(shuō)明 | 應(yīng)用于匹配正則表達(dá)式的代理資源的容器 |
---|---|
語(yǔ)法 | <ProxyMatch regex> ...</ProxyMatch> |
作用域 | server config, virtual host |
狀態(tài) | 擴(kuò)展(E) |
模塊 | mod_proxy |
<ProxyMatch>
和<Proxy>
指令基本相同,只是匹配字符串可以為正則表達(dá)式。
說(shuō)明 | 轉(zhuǎn)發(fā)請(qǐng)求的最大代理數(shù)目 |
---|---|
語(yǔ)法 | ProxyMaxForwards number |
默認(rèn)值 | ProxyMaxForwards 10 |
作用域 | server config, virtual host |
狀態(tài) | 擴(kuò)展(E) |
模塊 | mod_proxy |
兼容性 | 僅在 Apache 2.0 及以后的版本中可用 |
ProxyMaxForwards
指令指定了允許轉(zhuǎn)發(fā)請(qǐng)求的最大代理數(shù)目。這個(gè)設(shè)置是為了避免無(wú)限代理循環(huán)或DoS攻擊的發(fā)生。
ProxyMaxForwards 15
說(shuō)明 | 將一個(gè)遠(yuǎn)端服務(wù)器映射到本地服務(wù)器的URL空間中 |
---|---|
語(yǔ)法 | ProxyPass [path] !|url [key=value key=value ...]] |
作用域 | server config, virtual host, directory |
狀態(tài) | 擴(kuò)展(E) |
模塊 | mod_proxy |
該指令允許你將一個(gè)遠(yuǎn)端服務(wù)器映射到本地服務(wù)器的URL空間中,此時(shí)本地服務(wù)器并不充當(dāng)代理角色,而是充當(dāng)遠(yuǎn)程服務(wù)器的一個(gè)鏡像。path是一個(gè)本地虛擬路徑名,url是一個(gè)指向遠(yuǎn)程服務(wù)器的部分URL,并且不允許包含查詢(xún)字符串。
ProxyPass
指令時(shí),ProxyRequests
指令通常應(yīng)當(dāng)被設(shè)為 off 。假設(shè)本地服務(wù)器地址是:http://example.com/
,那么,
ProxyPass /mirror/foo/ http://backend.example.com/
將會(huì)導(dǎo)致對(duì)http://example.com/mirror/foo/bar
的本地請(qǐng)求將會(huì)在內(nèi)部轉(zhuǎn)換為一個(gè)代理請(qǐng)求:http://backend.example.com/bar
。
"!
"指令對(duì)于您不想對(duì)某個(gè)子目錄進(jìn)行反向代理時(shí)很有用。比如說(shuō):
ProxyPass /mirror/foo/i !
ProxyPass /mirror/foo http://backend.example.com
將會(huì)代理除/mirror/foo/i
之外的所有對(duì)backend.example.com
下/mirror/foo
的請(qǐng)求。
順序很重要,您需要把拒絕指令放置在普通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 JSESSIONID 或PHPSESSIONID ,
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.
說(shuō)明 | 調(diào)整由反向代理服務(wù)器發(fā)送的HTTP應(yīng)答頭中的URL |
---|---|
語(yǔ)法 | ProxyPassReverse [path] url |
作用域 | server config, virtual host, directory |
狀態(tài) | 擴(kuò)展(E) |
模塊 | mod_proxy |
此指令使Apache調(diào)整HTTP重定向應(yīng)答中Location
, Content-Location
, URI
頭里的URL。這樣可以避免在Apache作為反向代理使用時(shí),后端服務(wù)器的HTTP重定向造成的繞過(guò)反向代理的問(wèn)題。
只有明確指定的應(yīng)答頭會(huì)被重寫(xiě),其它應(yīng)答頭保持不變,并且HTML頁(yè)面中的URL也不會(huì)被修改。如果被代理的內(nèi)容包含絕對(duì)URL引用,那么將會(huì)繞過(guò)代理。有一個(gè)第三方模塊可以檢查并改寫(xiě)HTML中的URL引用,該模塊就是Nick Kew編寫(xiě)的mod_proxy_html。
path是本地虛擬路徑的名稱(chēng)。url是遠(yuǎn)端服務(wù)器的部分URL。與ProxyPass
指令中的使用方法相同。
例如,假定本地服務(wù)器擁有地址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/
不僅會(huì)把所有對(duì)http://example.com/mirror/foo/bar
的請(qǐng)求直接轉(zhuǎn)換為對(duì)http://backend.example.com/bar
的代理請(qǐng)求(由ProxyPass
提供的功能),它還會(huì)重定向服務(wù)器backend.example.com
的發(fā)送:當(dāng)http://backend.example.com/bar
被它重定向到http://backend.example.com/quux
時(shí),Apache會(huì)在轉(zhuǎn)交HTTP重定向應(yīng)答到客戶(hù)端之前調(diào)整它為http://example.com/mirror/foo/quux
。注意:被用于構(gòu)建URL的主機(jī)名與UseCanonicalName
指令的設(shè)置有關(guān)。
注意,此ProxyPassReverse
指令亦可與mod_rewrite
的代理穿透特性(RewriteRule ... [P]
)聯(lián)用。因?yàn)樗灰蕾?lài)于相應(yīng)的ProxyPass
指令。
當(dāng)在<Location>
配置段中使用時(shí),第一個(gè)參數(shù)會(huì)被忽略而采用由<Location>
指令指定的本地目錄。
說(shuō)明 | Adjusts the Domain string in Set-Cookie headers from a reverse- proxied server |
---|---|
語(yǔ)法 | ProxyPassReverseCookieDomain internal-domain public-domain |
作用域 | server config, virtual host, directory |
狀態(tài) | 擴(kuò)展(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.
說(shuō)明 | Adjusts the Path string in Set-Cookie headers from a reverse- proxied server |
---|---|
語(yǔ)法 | ProxyPassReverseCookiePath internal-path public-path |
作用域 | server config, virtual host, directory |
狀態(tài) | 擴(kuò)展(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.
說(shuō)明 | 使用進(jìn)入的HTTP請(qǐng)求頭來(lái)發(fā)送代理請(qǐng)求 |
---|---|
語(yǔ)法 | ProxyPreserveHost On|Off |
默認(rèn)值 | ProxyPreserveHost Off |
作用域 | server config, virtual host |
狀態(tài) | 擴(kuò)展(E) |
模塊 | mod_proxy |
兼容性 | 僅在 Apache 2.0.31 及以后的版本中可用 |
當(dāng)啟用時(shí),此選項(xiàng)將把傳入請(qǐng)求的"Host:"行傳遞給被代理的主機(jī),而不是傳遞在ProxyPass
中指定的主機(jī)名。
此選項(xiàng)一般為Off
狀態(tài)。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.
說(shuō)明 | 代理HTTP和FTP連接的接收緩沖區(qū)大小(字節(jié)) |
---|---|
語(yǔ)法 | ProxyReceiveBufferSize bytes |
默認(rèn)值 | ProxyReceiveBufferSize 0 |
作用域 | server config, virtual host |
狀態(tài) | 擴(kuò)展(E) |
模塊 | mod_proxy |
ProxyReceiveBufferSize
指令為增加的吞吐量指定了代理HTTP和FTP連接的(TCP/IP)網(wǎng)絡(luò)接收緩沖區(qū)。這個(gè)值必須大于512
,或設(shè)置為"0
"表示使用系統(tǒng)默認(rèn)的緩沖大小。
ProxyReceiveBufferSize 2048
說(shuō)明 | 用于處理某些特定請(qǐng)求的遠(yuǎn)端代理 |
---|---|
語(yǔ)法 | ProxyRemote match remote-server |
作用域 | server config, virtual host |
狀態(tài) | 擴(kuò)展(E) |
模塊 | mod_proxy |
此指令定義了此代理的遠(yuǎn)端代理。match可以是遠(yuǎn)端服務(wù)器支持的URL形式的名稱(chēng)、或是遠(yuǎn)端服務(wù)器使用的部分URL、或是代表服務(wù)器可以接受所有請(qǐng)求的"*
"。remote-server是遠(yuǎn)端服務(wù)器的部分URL。語(yǔ)法為:
remote-server = scheme://hostname[:port]
scheme是與遠(yuǎn)端服務(wù)器交換信息時(shí)使用的協(xié)議;本模塊暫時(shí)只支持http
協(xié)議。
ProxyRemote http://goodguys.com/ http://mirrorguys.com:8000
ProxyRemote * http://cleversite.com
ProxyRemote ftp http://ftpproxy.mydomain.com:8080
在最后一個(gè)例子中,代理會(huì)將封裝到另外一個(gè)HTTP代理請(qǐng)求中的FTP請(qǐng)求轉(zhuǎn)交到另外一個(gè)能處理它們的代理去。
此選項(xiàng)也支持反向代理配置:一個(gè)后端web服務(wù)器可以被嵌入到一個(gè)虛擬主機(jī)的URL空間中,哪怕它是由另一個(gè)代理轉(zhuǎn)交過(guò)來(lái)的。
說(shuō)明 | 處理匹配正則表達(dá)式的請(qǐng)求的遠(yuǎn)端代理 |
---|---|
語(yǔ)法 | ProxyRemoteMatch regex remote-server |
作用域 | server config, virtual host |
狀態(tài) | 擴(kuò)展(E) |
模塊 | mod_proxy |
ProxyRemoteMatch
與ProxyRemote
令基本相同。除了第一個(gè)參數(shù)是由一個(gè)請(qǐng)求的URL變成了匹配的正則表達(dá)式。
說(shuō)明 | 啟用正向(標(biāo)準(zhǔn))代理請(qǐng)求 |
---|---|
語(yǔ)法 | ProxyRequests On|Off |
默認(rèn)值 | ProxyRequests Off |
作用域 | server config, virtual host |
狀態(tài) | 擴(kuò)展(E) |
模塊 | mod_proxy |
此指令將允許或禁止Apache作為正向代理服務(wù)器的功能(設(shè)置為Off
并不會(huì)禁用ProxyPass
指令)。
在一個(gè)典型的反向代理配置中,此可選項(xiàng)一般設(shè)置為Off
。
為了能夠代理HTTP或FTP站點(diǎn),mod_proxy_http
或mod_proxy_ftp
必須同時(shí)存在于服務(wù)器中。
在您沒(méi)有對(duì)服務(wù)器采取安全措施之前,請(qǐng)不要用ProxyRequests
啟用您的代理。一個(gè)開(kāi)放的代理服務(wù)器不僅對(duì)您的網(wǎng)絡(luò)有威脅,對(duì)整個(gè)因特網(wǎng)來(lái)說(shuō)也同樣如此。
說(shuō)明 | 代理請(qǐng)求的網(wǎng)絡(luò)超時(shí) |
---|---|
語(yǔ)法 | ProxyTimeout seconds |
默認(rèn)值 | ProxyTimeout 300 |
作用域 | server config, virtual host |
狀態(tài) | 擴(kuò)展(E) |
模塊 | mod_proxy |
兼容性 | 僅在 Apache 2.0.31 及以后的版本中可用 |
此指令允許用戶(hù)對(duì)代理請(qǐng)求指定一個(gè)超時(shí)值。當(dāng)你有一個(gè)很慢/錯(cuò)誤多多的應(yīng)用服務(wù)器經(jīng)常掛起,而您寧愿返回一個(gè)超時(shí)的失敗信息也不愿意繼續(xù)等待不知道多久的時(shí)候,這個(gè)功能是很有用的。
說(shuō)明 | 控制代理對(duì)Via 應(yīng)答頭的使用 |
---|---|
語(yǔ)法 | ProxyVia On|Off|Full|Block |
默認(rèn)值 | ProxyVia Off |
作用域 | server config, virtual host |
狀態(tài) | 擴(kuò)展(E) |
模塊 | mod_proxy |
此指令控制代理對(duì)"Via:
"頭的使用。它的目的是控制位于代理服務(wù)器鏈中的代理請(qǐng)求的流向。參閱RFC 2616(HTTP/1.1)14.45小節(jié)以獲得關(guān)于"Via:
"頭的解釋。
Off
,將不會(huì)采取特殊的處理。如果一個(gè)請(qǐng)求或應(yīng)答包含"Via:
"頭,將不進(jìn)行任何修改而直接通過(guò)。On
每個(gè)請(qǐng)求和應(yīng)答都會(huì)對(duì)應(yīng)當(dāng)前主機(jī)得到一個(gè)"Via:
"頭。Full
,每個(gè)產(chǎn)生的"Via:
"頭中都會(huì)額外加入Apache服務(wù)器的版本,以"Via:
"注釋域出現(xiàn)。Block
,每個(gè)代理請(qǐng)求中的所有"Via:
"頭行都將被刪除。且不會(huì)產(chǎn)生新的"Via:
"頭。