mod_proxy_balancer + mod_disk_cache on Apache 2.2.3
Apache2.2.3ã®ç°å¢ä¸ã§ mod_proxy_balancer 㨠mod_disk_cache ã使ãããã£ãã·ã¥ãµã¼ããæ§ç¯ããã®ã§ã¡ã¢ãã¦ããã¾ãã
ã¤ã¡ã¼ã¸ããæ§æã¨ãã¦ã¯ãã¾ãããã³ãã¨ã³ãã«Apacheã®Reverse Proxy Serverããããããã¦ãã®è£å´ã«å®éã«ã¢ã¯ã»ã¹ããè¤æ°å°ã®Web Server(以ä¸ã®ä¾ã§ã¯5å°)ãããã¾ãã
ã¯ã©ã¤ã¢ã³ãããã®ã¢ã¯ã»ã¹ãåããã¨ããªãã¼ã¹ãããã·ã¯ãè² è·åæ£ã¢ã«ã´ãªãºã ã«ãããã£ã¦ãå®éã®ã¦ã§ããµã¼ãã¸ãªã¯ã¨ã¹ããæãããã¨ã«ãªãã¾ãããã®éãç»åã³ã³ãã³ãã®ã¿ããã£ãã·ã¥ãã次å以éã®ã¢ã¯ã»ã¹ã§ã¯ãã£ãã·ã¥ãã¡ã¤ã«ã®ã¿ãè¿ãããã«ãã¾ãã
ã¨ãããã¨ã§æ©éè¨å®ãã¦ã¿ã¾ãã
mod_proxy_balancerã¢ã¸ã¥ã¼ã«ãæå¹ã«ããããã«ã¯ãmod_proxyããã³mod_proxy_httpã¢ã¸ã¥ã¼ã«ãæå¹ã«ãªã£ã¦ããå¿ è¦ãããã¾ããã¾ããªãã¼ã¹ãããã·å´ã§mod_rewriteã使ãããå ´é¢ãããã®ã§ããããæå¹ã«ãã¦ããã¾ãã
LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_http_module modules/mod_proxy_http.so LoadModule proxy_balancer_module modules/mod_proxy_balancer.so LoadModule status_module modules/mod_status.so LoadModule rewrite_module modules/mod_rewrite.so ProxyRequests Off ProxyPassReverse / http://192.168.1.10/ ProxyPassReverse / http://192.168.1.11/ ProxyPassReverse / http://192.168.1.12/ ProxyPassReverse / http://192.168.1.13/ ProxyPassReverse / http://192.168.1.14/ <Proxy balancer://web-cluster> BalancerMember http://192.168.1.10 loadfactor=1 BalancerMember http://192.168.1.11 loadfactor=1 BalancerMember http://192.168.1.12 loadfactor=1 BalancerMember http://192.168.1.13 loadfactor=1 BalancerMember http://192.168.1.14 loadfactor=1 </Proxy> RewriteEngine on RewriteRule ^/balancer_manager$ /balancer_manager [L] LoadModule cache_module modules/mod_cache.so <IfModule mod_cache.c> LoadModule disk_cache_module modules/mod_disk_cache.so <IfModule mod_disk_cache.c> # mkdir -p /www/example.com/proxy # chown nobody:nobody /www/example.com/proxy CacheRoot /www/example.com/proxy # CacheEnable disk / CacheEnable disk /images CacheEnable disk /icons CacheDirLevels 5 CacheDirLength 3 # unit is second CacheDefaultExpire 3600 </IfModule> </IfModule> # Balancer: Remote Web Servers RewriteRule ^/(.*)$ balancer://web-cluster/$1 [P] <Location /balancer_manager> SetHandler balancer-manager Order Deny,Allow Deny from all Allow from 192.168.1.20 </Location>
ãã£ã¹ã¯ãã£ãã·ã¥æ©è½ã¯å®ç¨ã¬ãã«ã«éãã¦ããã®ã§ãä»åã¯ãã£ã¹ã¯ã«ãã£ãã·ã¥æ©è½ãæå¹ã«ãã¾ãã
ã¾ãäºåã«ãã£ã¬ã¯ããªãä½æãã¦ããå¿ è¦ãããã¾ãã
# mkdir -p /www/example.com/proxy # chown nobody:nobody /www/example.com/proxy
è¨å®ãã¹ããã£ã¬ã¯ãã£ãã¯ãããã¥ã¡ã³ããåèã«ãã¦ä¸ããã
以ä¸ã®ä¾ã§ã¯ãimages/ 㨠icons/ 以ä¸ã®ã³ã³ãã³ãããã£ã¹ã¯ä¸ã«ãã£ãã·ã¥ãããã¨ã«ãªãã¾ããã¾ããã£ãã·ã¥ã®æå¹æéã¯1æ¥ã«è¨å®ãã¦ããã¾ãã
LoadModule cache_module modules/mod_cache.so <IfModule mod_cache.c> LoadModule disk_cache_module modules/mod_disk_cache.so <IfModule mod_disk_cache.c> CacheRoot /www/example.com/proxy # CacheEnable disk / CacheEnable disk /images CacheEnable disk /icons CacheDirLevels 5 CacheDirLength 3 # unit is second CacheDefaultExpire 3600 </IfModule> </IfModule>
ã³ã³ãã³ãããã£ãã·ã¥å¯è½ãã©ããã®å¤å®ã¯ä»¥ä¸ã®æ¡ä»¶ã«å¾ãã¾ãã
ã»ãªã¯ã¨ã¹ããããURLã«ããã¦ãã£ãã·ã³ã°ãæå¹ã§ãããã¨
ã»ã¬ã¹ãã³ã¹ã¯HTTPã¹ãã¼ã¿ã¹ã200,203,300,301ããã³410ã§ãããã¨
ã»GETãªã¯ã¨ã¹ãã§ãããã¨
ã»ãªã¯ã¨ã¹ãã«Authorization:ããããããå ´åã¯ãã£ãã·ã¥ããªã
ã»ã¬ã¹ãã³ã¹ã«Authorization:ããããããå ´åã¯ãåæã«Cache-Control:ãããã§ãs-maxageããmust-revalidateããããã¯ãpublicããªãã·ã§ã³ãæå®ããã¦ãããã¨
ã»URLã«ã¯ã¨ãªæååãããå ´åã¯ããã®ã¬ã¹ãã³ã¹ã«Expires:ãããããªãéããã£ãã·ã¥ããªã
ã»ã¬ã¹ãã³ã¹ã®HTTPã¹ãã¼ã¿ã¹ã200(OK)ã®å ´åãCacheIgnoreNoLastModãã£ã¬ã¯ãã£ããæå®ããã¦ããªãéããåæã«Etag:ãLast-Modified:ãããã¯Expires:ãããã®å°ãªãã¨ãã²ã¨ã¤ãåå¨ããªããã°ãªããªã
ã»ããã¬ã¹ãã³ã¹ã®ãCache-Controlããããã«ãprivateããªãã·ã§ã³ãæå®ããã¦ããå ´åãCacheStorePrivateãã£ã¬ã¯ãã£ããæå®ããã¦ããªãéããã£ãã·ã¥ããªã
ã»åæ§ã«ãã¬ã¹ãã³ã¹ã®ãCache-Controlããããã«ãno-storeããªãã·ã§ã³ãæå®ããã¦ããå ´åãCacheStoreNoStoreãã£ã¬ã¯ãã£ããæå®ããã¦ããªãéããã£ãã·ã¥ããªã
ã»ã¬ã¹ãã³ã¹ã®ãVary:ããããã«ããããªã¼ã«ã*ããæå®ããã¦ããå ´åã¯ãã£ãã·ã¥ããªã
ä¸è¨ã®ãã£ã¹ã¯ãã£ãã·ã¥æ©è½ã®è¨å®ã追è¨ããã®ãã以ä¸ã®è¨å®ãã¡ã¤ã«ã«ãªãã¾ãã
LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_http_module modules/mod_proxy_http.so LoadModule proxy_balancer_module modules/mod_proxy_balancer.so LoadModule status_module modules/mod_status.so LoadModule rewrite_module modules/mod_rewrite.so ProxyRequests Off ProxyPassReverse / http://192.168.1.10/ ProxyPassReverse / http://192.168.1.11/ ProxyPassReverse / http://192.168.1.12/ ProxyPassReverse / http://192.168.1.13/ ProxyPassReverse / http://192.168.1.14/ <Proxy balancer://web-cluster> BalancerMember http://192.168.1.10 loadfactor=1 BalancerMember http://192.168.1.11 loadfactor=1 BalancerMember http://192.168.1.12 loadfactor=1 BalancerMember http://192.168.1.13 loadfactor=1 BalancerMember http://192.168.1.14 loadfactor=1 </Proxy> RewriteEngine on RewriteRule ^/balancer_manager$ /balancer_manager [L] LoadModule cache_module modules/mod_cache.so <IfModule mod_cache.c> LoadModule disk_cache_module modules/mod_disk_cache.so <IfModule mod_disk_cache.c> # mkdir -p /www/example.com/proxy # chown nobody:nobody /www/example.com/proxy CacheRoot /www/example.com/proxy # CacheEnable disk / CacheEnable disk /images CacheEnable disk /icons CacheDirLevels 5 CacheDirLength 3 # unit is second CacheDefaultExpire 3600 </IfModule> </IfModule> # Balancer: Remote Web Servers RewriteRule ^/(.*)$ balancer://web-cluster/$1 [P] <Location /balancer_manager> SetHandler balancer-manager Order Deny,Allow Deny from all Allow from 192.168.1.20 </Location>
注æãã¹ãç¹ãããã¤ãããã¾ãã
- è² è·åæ£ãè¡ãªãå ´åãåãµã¼ãã®ã³ã³ãã³ãã«éããããã¨ãã£ãã·ã¥ãããé½åº¦ãµã¼ãã¸ã®ã¢ã¯ã»ã¹ãçºçãã
- æå¹æéãåããåã«ã³ã³ãã³ãã®ä¸èº«ãå¤æ´ããå ´åããã£ãã·ã¥ãã¬ã¹ãã³ã¹ã¨ãã¦è¿ã
- æå¹æéãåããåã«ã³ã³ãã³ããåé¤ããå ´åããã£ãã·ã¥ãã¬ã¹ãã³ã¹ã¨ãã¦è¿ã