æ°ãããï¼
- ãªãProxyPassReverseã«balancer://~~ ãè¨å®ã§ããªãã®ã *1
- ãªãProxyPassReverseã«ajp://~~ ãè¨å®ã§ããªãã®ã
- ãªãbackendãhttpã¨ajpã®å ´åã§ãProxyPassReverseã«è¨å®ããURLãç°ãªãã®ã
ãªã©ãªã©ãä»ã¾ã§ã¯mod_proxyããæ©ä¼ãã»ã¨ãã©ãªãé©å½ã«ãè¶ãæ¿ãã¦ããã®ã§ãä¸éã®äººããç¸å½é ãã¦ããã¨ã¯æãã¾ããããã£ãããªã®ã§èªåç¨ã¾ã¨ããæãã¤ãããã¨ãã¤ãã¤ãã¨ã¡ã¢ã£ã¦ããããããªãåé·ã§ããã
è¿½è¨ 20100907
apache 2.2.12 ãããbalancer:// ã®URLã«ãProxyPassReverseã使ããããã«mod_proxyããã¯ã¼ã¢ãããã¦ãã¾ããã
*) mod_proxy: Complete ProxyPassReverse to handle balancer URL's. Given;
BalancerMember balancer://alias http://example.com/foo
ProxyPassReverse /bash balancer://alias/bar
backend url http://example.com/foo/bar/that is now translated /bash/that
[William Rowe]
ã¨ããããã§ãè¨è¿°ãã¹ãããªããã®ã§apache 2.2.12ã¯ProxyPassReverse balancer://~~ ã§æ¸ããã»ããè¯ãããããã¾ããã(試ãã¦ãªãã®ã§ä½ã¨ãè¨ããªããã©)
ããã«è¿½è¨
å®éã«è©¦ãã¦ã¿ããã©ãProxyPassReverse balancer://~~ ããã¾ãåä½ããã®ã¯ãBalancerMemberãhttpã®ã¨ãã§ãajp:// ã ã¨Locationãããã調æ´ã§ãã¦ãªãã£ãã3çªã®é ç®ã®ã¨ãã§ãæ¸ãããã©ãhttpã¨ajpãããã³ã«å©ç¨æã®ã¬ã¹ãã³ã¹ãããã®éãé¢ä¿ãã¦ãããããªããã¨æ¨æ¸¬ã
## 追è¨ããã¾ã§
- http://httpd.apache.org/docs/2.2/ja/mod/mod_proxy.html
- http://httpd.apache.org/docs/2.2/ja/mod/mod_proxy.html#proxypass
- http://httpd.apache.org/docs/2.2/ja/mod/mod_proxy.html#proxypassreverse
èªåãªãã«ç解ã§ãã¦ç´å¾ãã¦ããã¤ããã§ããã確èªã«ä½¿ã£ãbackendãµã¼ãã¯apache + ç°¡åãªcgi, tomcatã®ããã©ã«ãã®webappsã ããªã®ã§ééã£ã¦ããã¨ãããããããããã¾ãããææããã ããã¨å¹¸ãã§ãã
æ§æ
確èªã§ä½¿ã£ãã®ã¯vmwareç°å¢ã«ä½ã£ãapache(reverse proxy)ã¨ãbackendã¯apache or tomcatã
reverse proxy backend server -------- http ----------- http or ajp ------------------- |client| <======> | apache | <======> | apache or tomcat| -------- ----------- -------------------
- clientãã¢ã¯ã»ã¹ããhostã¯www.example.com
- reverse proxyã§ããapacheãã¢ã¯ã»ã¹ããbackendã®hostã¯backend*.example.com
- backendã®apacheã¯ã®UseCannonicalName, UseCannonicalPhysicalPortãOffã«ãªã£ã¦ããã¨ãã
ProxyPassReverse
ProxyPassReverse ãã£ã¬ã¯ãã£ã
説æ: ãªãã¼ã¹ãããã·ããããµã¼ãããéããã HTTP å¿çãããã® URL ã調æ´ãã
æ§æ: ProxyPassReverse [path] url
apacheå
¬å¼ã®èª¬æã®ããã«ãProxyPassReverseã§è¨å®ããã®ã¯ããã¯ã¨ã³ããµã¼ãããéããã¦ããLocationãããçã®URLã§ãæ¸ãæããããURLãè¨å®ãããæ¸ãæããè¡ãããã®ã¯ä¸è´ããã¨ããªã®ã§æ£ããæ¸ããªããã°ãããªãã
ä¾ãã°ä¸2è¡ã®è¨å®ãbackend1ã®apacheãport80ã§listenãã¦ããã°ãURLã¨ãã¦ã¯å®è³ªåãæå³ã ãã©ãProxyPassReverseã®è¨å®ã¨ãã¦ã¯å¥ç©(å¾è¿°).
ProxyPass /app http://backend1.example.com:80/app ProxyPass /app http://backend1.example.com/app
URLãæ¸ãæããããã¨ãã¨ã¯
ä¾ãã°ãããªProxyPassè¨å®ã®ã¨ãã
ProxyPass /app http://backend1.example.com:8080/app
ãã®ã¨ãclientãhttp://www.example.com/app 以ä¸ã«ã¢ã¯ã»ã¹ããã¨ãreverse proxyã®apacheã¯backendã®ãµã¼ãã«ã¢ã¯ã»ã¹ããããã®ã¨ããbackendãµã¼ãå´ã§redirectãçºçããå ´åã«ProxyPassReverseã®åºçªãè¯ãããã®ã¯ãã£ã¬ã¯ããªã«ã¹ã©ãã·ã¥ãªãã§ã¢ã¯ã»ã¹ããå ´åãä»ã«ãã¢ããªå´ã§ç¹å®URLã«ãªãã¤ã¬ã¯ããããå ´åãªã©ã
- clientãhttp://www.example.com/app/dir ã«ã¢ã¯ã»ã¹
- ãªã¯ã¨ã¹ããåãåã£ãapache(reverse proxy)ããbackendã®http://backend1.example.com:8080/app/dirã«ã¢ã¯ã»ã¹
- backendã®apacheã¯301ã§Locationãããã«ã¹ã©ãã·ã¥ãä»ããURL(http://backend1.example.com:8080/app/dir/)ãreverse proxyã®apacheã«è¿ã
- reverse proxyã®apacheã¯backendããåãåã£ãHTTPã¬ã¹ãã³ã¹ãclientã«è¿ã
åé¡ã¯ãã®ã¨ãã®3çªã®HTTPããã(ã®Locationããã)ãreverse proxyã§ããapacheã¯backendã®ãµã¼ãã«å¯¾ãã¦http://backend1.example.com:8080/ã§ã¢ã¯ã»ã¹ãã¦ããã®ã§ãbackendããåãåãHTTPãããã¯ä»¥ä¸ã®ãããªãã®ã
HTTP/1.1 302 Moved Temporarily Date: Sat, 05 Dec 2009 03:08:13 GMT Server: Apache Location: http://backend1.example.com:8080/app/dir/ Transfer-Encoding: chunked Content-Type: text/plain
ãã®ããããclientã«è¿ã£ã¦ãã¾ãã¨ãclientã¯Locationãããã®å¤ã§ããhttp://backend1.example.com:8080/app/dir/ ã«ç´æ¥ã¢ã¯ã»ã¹ãããã¨ãã¦ãã¾ãã
clientãbackendã®ãµã¼ãã«ç´æ¥ã¢ã¯ã»ã¹ããã¨ãªããã¡ã
è²ã ãããã©ã
- ä»çµã¿ãã°ãã¦ãã£ãæªã
- reverse proxyã§éçã³ã³ãã³ãã極åå¿çãããã®ã«ãç´æ¥backendã®ã¢ããªã±ã¼ã·ã§ã³ãµã¼ãã«ã¢ã¯ã»ã¹ããããè² è·ãé«ããªã
- ããããbackend1.example.comãDNSã§åå解決ã§ããªã or backendããã©ã¤ãã¼ãIPã®LANã«ãã or Firewallã§éãããã¦ããçã®å ´åã¯clientãbackendã«ã¢ã¯ã»ã¹ã§ããªã
- ex) /etc/hostsã« 10.0.0.10 backend1 ãè¨å®
- ProxyPass /app http://backend1:8080/app ã¨è¨å®ãã¦ããå ´åãªã©
ãªã©ã®äºæ ããããããreverse proxyã¯backendããä¸è¨ã®ãããªLocationããããè¿ã£ã¦ããã¨ãã«Locationãããã調æ´ããå¿ è¦ãããããããå®éã«è¡ãã®ãProxyPassReverseã調æ´ãããURLã¨ã¯ã¾ãã«http://backend1.example.com:8080/app ãªã®ã§ãapacheã®è¨å®ã¯
ProxyPass /app http://backend1.example.com:8080/app ProxyPassReverse /app http://backend1.example.com:8080/app
ãããªãã
ãªãProxyPassReverseã«balancer://~~ ãè¨å®ã§ããªãã®ããã®çã
ããã§1çªã®çããâã®ä¾ã®ããã«ProxyPassReverseã«è¨å®ããã®ã¯backendããè¿ã£ã¦ããLocationãããçã®URLã調æ´ããããã®ãã®ã
ãªã®ã§ãProxyPassã¨ã»ããã«ãã¦ProxyPassReverseã«balancer://~~ ãæ¸ãã¦ãæå³ã¯ãªããbackendã®ãµã¼ãããbalancer://~~ ã¨ãããLocationããããè¿ã£ã¦ããã¯ãã¯ãªãã®ã ããã
ProxyPass /app balancer://cluster/app ProxyPassReverse /app balancer://cluster/app ## ééã
ProxyPassReverseã®URLã¯BalancerMember or ProxyPassã«è¨å®ããURLã¨ã¯å¿ ãããä¸è´ããªã
ãããå¾®å¦ã«ã¯ã¾ã£ããå®ç°å¢ã§ã¯ãããªãã°ãã°ãªè¨å®ã¯ãªããããããªããã©ã
2ã¤ã®backendã®apacheãããããportã80/8080ã§listenãã¦ããã®ã§ãBalancerManagerã«æ¸ãã¨ãã«portãæ示çã«æ¸ãã¦ããã
- reverse proxyã«è¨å®ããbalancer
<Proxy balancer://cluster > BalancerMember http://backend1.example.com:80 BalancerMember http://backend2.example.com:8080 </Proxy>
èå¿ã®Proxyããè¨å®ããããééãããã¦ã£ããBalancerMemberã¨åãå¤ã§è¯ãã¨æãããã§æ¬¡ã®è¨å®ã«ãã¦ãããbackend1ã«ãã£ãã¨ãã¯æ£å¸¸ã«åããªãã
ProxyPass /app balancer://cluster/app ProxyPassReverse /app http://backend1.example.com:80/app # 1 ProxyPassReverse /app http://backend2.example.com:8080/app
æ£è§£ã¯ãã£ã¡ã
ProxyPass /app balancer://cluster/app ProxyPassReverse /app http://backend1.example.com/app # 2 ProxyPassReverse /app http://backend2.example.com:8080/app
ãªããã
reverse proxyãbackend1ã®apacheã«ã¢ã¯ã»ã¹ããã¨ãã«ãhttp://backend1.example.com:80/ã¨portæå®ã§
ã¢ã¯ã»ã¹ããã¨ãã¦ããbackendã®ãµã¼ãã¯portçªå·ãä»ããã«ã
Location: http://backend1.example.com/app
ã§HTTPããããè¿ãã¦ãããProxyPassReverseãæ¸ãæããã®ã¯ããã®ã¨ãè¿ã£ã¦ãããããã®URLãªã®ã§ã#1ã®è¨å®ã¯ééããapacheãdefaultã®80çªã§listenãã¦ããå ´åãURLã®æå³ã¨ãã¦ã¯#1ã#2ãåãã ãã©ProxyPassReverseã®è¨å®ã¨ãã¦ã¯å¥ã
backendãajpã®å ´å
ajpãããã³ã«ã®ä»æ§ãç¥ããªãã®ã§çµé¨ãå ã«ããæ¨æ¸¬ã§ãããajpã§æ¸¡ãå ´åã¯ã
ProxyPass /app ajp://localhost:8009/app
ã¨æ¸ããã¨ãã¦ãtomcatã«æ¸¡ãããhostãããã¯localhostã§ã¯ãªãã¦ãclientãå ã ã¢ã¯ã»ã¹ãã¦ããwww.example.comã®ã¾ã¾ã£ã½ãããªã®ã§ãtomcatå´ã§redirectãçºçãã¦ããtomcatããreverse proxyã§ããapacheã«è¿ã£ã¦ããLocationãããã®hostã¯www.exmaple.comã®ã¾ã¾ã ã£ãã
åãURLã®æ§æã§backendã«proxyããå ´å
URLãåãæ§æã§backendã®ajpã«æ¸¡ãå ´åã¯Locationãããã®èª¿æ´ã¯å¿ è¦ãªãã®ã§ProxyPassReverseããããªãã½ãï¼
- clientãhttp://www.example.com/app/dir ã«ã¢ã¯ã»ã¹
- ãªã¯ã¨ã¹ããåãåã£ãreverse proxyããbackendã®ajp://backend1.example.com:8009/app/dirã«ã¢ã¯ã»ã¹
- backendã®tomcatã¯301ã§Locationãããã«ã¹ã©ãã·ã¥ãä»ããURLãreverse proxyã«è¿ã
- reverse proxyã¯backendããåãåã£ãHTTPã¬ã¹ãã³ã¹ãclientã«è¿ã
ãã®ã¨ãã®3ã®HTTPãããã¯
HTTP/1.1 302 Moved Temporarily Date: Sat, 05 Dec 2009 04:23:11 GMT Location: http://www.example.com/app/dir/ Content-Type: text/plain
ã ã£ãã®ã§ãããã®èª¿æ´ã¯ä¸è¦ãªã®ãããã
ProxyPass /app ajp://backend1.example.com:8009/app #ProxyPassReverse /app http://www.example.com/app ## ãããä¸è¦
URLãå¤ãã¦æ¸¡ãå ´å
ãã®ã¨ãã¯ProxyPassReverseã¯å¿ è¦ãªã¯ããä¾ãã° /app => backendã®/fooã«æ¸¡ãå ´å
ProxyPass /app ajp://backend1.example.com:8009/foo
- clientãhttp://www.example.com/app/dir ã«ã¢ã¯ã»ã¹
- ãªã¯ã¨ã¹ããåãåã£ãreverse proxyããbackendã®ajp://backend1.example.com:8009/foo/dirã«ã¢ã¯ã»ã¹
- backendã®tomcatã¯301ã§Locationãããã«ã¹ã©ãã·ã¥ãä»ããURLãreverse proxyã«è¿ã
- reverse proxyã¯backendããåãåã£ãHTTPã¬ã¹ãã³ã¹ãclientã«è¿ã
ãã®ã¨ãã®3ã®HTTPãããã¯
HTTP/1.1 302 Moved Temporarily Date: Sat, 05 Dec 2009 04:26:25 GMT Location: http://www.example.com/foo/dir/ Content-Type: text/plain
ã ã£ããclientãã¢ã¯ã»ã¹ããéã®é ã®/appã/fooã«å¤ãã£ã¦ãã¾ã£ã¦ãããhttpã¨éã£ã¦FQDNã¯backend1ã«ã¯ãªã£ã¦ããããwww.example.comã®ã¾ã¾ãªãã¨ããã¤ã³ãã
tomcatå´ããããã¨ãreverse proxyã®apacheãajp://backend1.example.com:8009/fooã«ã¢ã¯ã»ã¹ããããã"/app"ãªãã¦ãã®ã¯å ¨ãé¢ç¥ããªãã¨ãããªã®ã§ããã¶ããããªã£ã¦ããï¼ ãã®ã¾ã¾ã ã¨ãclientãééã£ãURLã«ãªãã¤ã¬ã¯ãããã®ã§ã
ProxyPass /app ajp://backend1.example.com:8009/foo ProxyPassReverse /app http://www.example.com/foo
ã®è¨å®ãæ¸ãã¦ãããªãã¨ãããªãã
ãã®è¾ºãã¾ã§ç解ã§ããããã®ã§ãåé ã®2çªã3çªã®çããåºãã
ãªãProxyPassReverseã«ajp://~~ ãè¨å®ã§ããªãã®ããã®çã
ä½åãæ¸ãã¦ããã©ProxyPassReverseã«æ¸ãã®ã¯backendããè¿ã£ã¦ããLocationãããçã調æ´ããããã®è¨å®ãclient <=>(http) apache <=>(ajp) tomcatã¨éä¿¡ãã¦ããLocationãããã¯clientãããããã¢ã¯ã»ã¹ããhttp://www.exmaple.com/~~ ã«ãªãã®ã§ProxyPassã«ajp://~~ãè¨å®ãã¦ãæå³ããªãã
ãªãbackendãhttpã¨ajpã®å ´åã§ãProxyPassReverseã«è¨å®ããURLãç°ãªãã®ããã®çã
backendãhttpã®å ´åã¯ProxyPassReverseã«è¨å®ããã®ã¯http://backend1.example.com/ãããã«å¯¾ãã¦ãajpã®å ´åã¯ãclientãã¢ã¯ã»ã¹ããhttp://www.example.com/ ã
ã§ãããã¯ç¢ºè¨¼ããªãã¦äºæ³ãªãã ãã©ãajpãããã³ã«ã®å ´åãLocationãããçã«ä½¿ç¨ãããFQDNã¯apacheãtomcatã«ajpã§æ¥ç¶ããã¨ãã®hoståã§ã¯ãªããå ã clientãã¢ã¯ã»ã¹ãããããæ å ±ã使ããã¦ããããã§ãªããã¨ã
httpã®å ´åã¯ãreverse proxyãbackendã«æ¥ç¶ããå ´åã
- client: reverse proxy
- server: backend apache server
ã¨ããé¢ä¿ã«ãªãã®ã§ã(UseCannonicalNameã®è¨å®ã«ä¾åãããã©) reverse proxyã®apacheã¯ProxyPassã«è¨å®ãã¦ããhoståã§backendã«æ¥ç¶ãã«ããã®ã§ãbackendã®apacheã¯Locationãããã§http://backend1.example.com/~~ ã®URLãè¿ãããã«ãªãããã®éãã
ãã¾ã
ãã¨ãProxyPassReverseã«æ¸ãURLã¯ãããããé ã«é©ç¨ãããã®ã§ã
(ãããªproxyã®ä»æ¹ããªããããããªããã©)
ProxyPass /baz balancer://cluster ProxyPass /foo balancer://cluster/foo
ãã®å ´åã¯ã/bazã«ã¤ãã¦ã®ProxyPassReverseãå¾ã«æ¸ãå¿ è¦ãããã
- ééã
ProxyPassReverse /baz http://backend1.example.com:8080 ProxyPassReverse /foo http://backend1.example.com:8080/foo
- æ£è§£
ProxyPassReverse /foo http://backend1.example.com:8080/foo ProxyPassReverse /baz http://backend1.example.com:8080 # ãã£ã¡ãå¾ã«
/bazã®è¨å®ãå
ã«æ¸ãã¦ãã¾ãã¨ã/fooã¸ã®ãªã¯ã¨ã¹ãã«å¯¾ãã¦ã®Locationãããã調æ´ããã¦ãã¾ã£ã¦ãhttp://backend1.example.comã®é¨åãhttp://www.example.com/bazã«æ¸ãæãããããçµæã¨ãã¦http://www.example.com/baz/foo ã«ãªã£ã¦ãã¾ãã
è¨å®ã¾ã¨ã
ä¸è¨ã®ãã¨ãã¾ã¨ããã¨ããã¶ããããªæãã«ãªãã
backendãhttp
åºæ¬çã«ProxyPassã¨åããã®ãæ¸ãã°è¯ãã
- 1å°ã®å ´å
ProxyPass /app http://backend1.example.com:8080/app ProxyPassReverse /app http://backend1.example.com:8080/app
- è¤æ°å°ã§balancerãã¦ãã¨ã
<Proxy balancer://cluster/ > BalancerMember http://backend1.example.com:8080 BalancerMember http://backend2.example.com:8080 </Proxy> ProxyPass /app blancer://cluster/app ProxyPassReverse /app http://backend1.example.com:8080/app ProxyPassReverse /app http://backend2.example.com:8080/app
backendãajp
URLãå¤æãã¦proxyãã¦ããå ´åã¯è¨å®ãå¿ è¦ãURLããã£ãããã®ã¾ã¾æ¸¡ãã¦ããå ´åã¯ProxyPassReverseã¯ãããªããã¨ã¯ããæ¸ãã¦ãåé¡ã¯ãªãã¨æãã®ã§ãæ¸ãã¦ãã¾ã£ã¦ã¦ãè¯ãããã
- 1å°ã®å ´å: URLããã®ã¾ã¾æ¸¡ãã¦ãã
ProxyPass /app ajp://backend1.example.com:8009/app ProxyPassReverse /app http://www.example.com/app ## âãããªã
- 1å°ã®å ´å: URLãå¤æ´ãã¦ãã
ProxyPass /app ajp://backend1.example.com:8009/foo/app ProxyPassReverse /app http://www.example.com/foo/app
- è¤æ°å°ã§balancer: URLããã®ã¾ã¾æ¸¡ãã¦ãã
<Proxy balancer://cluster > BalancerMember ajp://backend1.example.com:8009 BalancerMember ajp://backend2.example.com:8009 </Proxy> ProxyPass /app blancer://cluster/app ProxyPassReverse /app http://www.example.com/app ## âãããªã
- è¤æ°å°ã§balancer: URLãå¤æ´ãã¦ãã
<Proxy balancer://cluster > BalancerMember ajp://backend1.example.com:8009 BalancerMember ajp://backend2.example.com:8009 </Proxy> ProxyPass /app blancer://cluster/foo/app ProxyPassReverse /app http://www.example.com/foo/app
追è¨
ProxyPassReverseCookiePathã¨CookieDomain
- http://httpd.apache.org/docs/2.2/ja/mod/mod_proxy.html#proxypassreversecookiedomain
- http://httpd.apache.org/docs/2.2/ja/mod/mod_proxy.html#proxypassreversecookiepath
ProxyPassReverseã¯Locationãããã調æ´ãããããã¨åæ§ã«ãã¢ããªã«ãã£ã¦ã¯Cookie(Set-Cookieããã)ã®pathãdomainã調æ´ããªãã¨ãããªããä»çµã¿ã¯ProxyPassReverseã¨åãã
clientãã¢ã¯ã»ã¹ãã¦ããURLã®pathã¨backendã®ã¢ããªãè¿ãSet-Cookieã®pathã¯å¿ ãããä¸è´ããªããç½®æããå¿ è¦ãããå ´åã«ãreverse proxyãã¦ããapacheã«è¨å®ããã
ProxyPass /foo http://backend.example.com/bar ProxyPassReverse /foo http://backend.example.com/bar
clientã http://www.example.com/foo/hoge.cgiã«ã¢ã¯ã»ã¹ããã¨reverse proxyã¯http://backend.example.com/bar/hoge.cgiã«ããããã®cgiã
Set-Cookie: id=100; path=/bar
ã®ãããªcookieããããè¿ãå ´åããã®ã¾ã¾ã§ã¯pathãå¤ãã£ã¦cookieãåããªãã®ã§ProxyPassReverseCookiePathã使ãã
### 20140824 ä¿®æ£ ã³ã¡ã³ãã§ææããã ããã®ã§ä¿®æ£ãã¾ããï¼
ProxyPassReverseCookiePath /bar /foo
âééã£ã¦ããæ¸ãã¦ãã¾ã£ã¦ãã¾ããã
ProxyPassReverseCookiePath /foo /bar
ã¾ããåæ§ã«Set-Cookieå ã®domainãç½®æããå ´åã¯ãProxyPassReverseCookieDomainã§ããã®è¨å®ã¯ä»ã¨éã£ã¦ãreverse proxyå ã®domainãå ã«æ¸ãã®ã§æ³¨æã
ProxyPassReverseCookieDomain backend.example.com www.example.com