Apache HTTP Server Version 2.2
¿øÀúÀÚ
Ralf S. Engelschall <rse@apache.org>
1997³â 12¿ù
ÀÌ ¹®¼´Â mod_rewrite
ÂüÁ¶ ¹®¼¸¦ º¸ÃæÇÑ´Ù.
ÀÌ ¹®¼´Â À¥°ü¸®ÀÚ°¡ ½ÇÁ¦ ÀÛ¾÷¿¡¼ ºÎµúÄ¡°ÔµÇ´Â ÀüÇüÀûÀÎ
URL°ü·Ã ¹®Á¦¸¦ ÇØ°áÇϱâÀ§Çؼ ¾î¶»°Ô ¾ÆÆÄÄ¡
mod_rewrite
¸¦ »ç¿ëÇÏ´ÂÁö ¼³¸íÇÑ´Ù. URL
ÀçÀÛ¼º ±ÔÄ¢À» ¼³Á¤ÇÏ¿© ¹®Á¦¸¦ ÇØ°áÇÏ´Â ¹æ¹ýÀ» ÀÚ¼¼È÷ ¼³¸íÇÑ´Ù.
mod_rewrite
¼Ò°³¾ÆÆÄÄ¡ mod_rewrite
¸ðµâÀº ±²ÀåÇÏ´Ù.
Áï, URLÀ» Á¶ÀÛÇÒ ¼ö ÀÖ´Â °·ÂÇÏ°í ½Ç·Î Á¤±³ÇÑ ¸ðµâÀÌ´Ù.
»ó»óÇØ¿Ô´ø °ÅÀÇ ¸ðµç Á¾·ùÀÇ URL Á¶ÀÛÀÌ °¡´ÉÇÏ´Ù. ±×·¯³ª
±× ´ë°¡·Î »ç¿ëÇϱ⠺¹ÀâÇÏ´Ù. mod_rewrite
ÀÇ
ÃÖ´ë ´ÜÁ¡Àº Ãʺ¸ÀÚ°¡ ÀÌÇØÇÏ°í »ç¿ëÇϱ⠽±Áö ¾Ê´Ù´Â Á¡ÀÌ´Ù.
½ÉÁö¾î ¾ÆÆÄÄ¡ Àü¹®°¡µµ Á¾Á¾ mod_rewrite
ÀÇ
»õ·Î¿î ¿ëµµ¸¦ ¹ß°ßÇÑ´Ù.
´Ù¸¥ ¸»·Î: mod_rewrite
¿¡ ´ëÇØ ´ç½ÅÀº
óÀ½¿¡ °ÌÀ» ¸Ô°í Àý´ë·Î ´Ù½Ã »ç¿ëÇÏÁö ¾Ê°Å³ª, °·ÂÇÔ¿¡ ¸Å·áµÇ¾î
¾ÕÀ¸·Î »î µ¿¾È »ç¶û¿¡ ºüÁú °ÍÀÌ´Ù. ÀÌ ±ÛÀº ù¹ø° °æ¿ì¸¦
¸·±âÀ§ÇØ ÀÌ¹Ì ¾Ë·ÁÁø ¸î°¡Áö ¼º°ø»ç·Ê¸¦ ¼Ò°³ÇÏ·Á°í ÇÑ´Ù.
ÀÌÁ¦ ³»°¡ Á÷Á¢ ¸¸µé¾ú°Å³ª ´Ù¸¥ »ç¶÷µéÀÌ ¸¸µç ¸¹Àº ½Ç¿ëÀûÀÎ ÇØ°áÃ¥ÀÌ ³ª¿Â´Ù. ¿¹Á¦¿¡¼ URL ÀçÀÛ¼ºÀÇ È渶¼úÀ» ¸¶À½²¯ ¹è¿ì±æ ¹Ù¶õ´Ù.
mod_alias
, mod_userdir
µîÀ» »ç¿ëÇÑ´Ù¸é [PT]
Ç÷¡±×¸¦ Ãß°¡ÇÑ´Ù. ȤÀº
ÁÖ¼¹ö¼³Á¤/°¡»óÈ£½ºÆ® »ç¿ëÀå¼Ò°¡ ¾Æ´Ñ .htaccess
»ç¿ëÀå¼Ò¿¡ ¾Ë¸Â°Ô ±ÔÄ¢À» ¼öÁ¤ÇÒ ¼öµµ ÀÖ´Ù. »ç¿ëÇϱâ Àü¿¡
Ç×»ó ±ÔÄ¢ÀÌ ¾î¶² ±â´ÉÀ» ÇÏ´ÂÁö ÀÌÇØÇϵµ·Ï Çضó. ±×·¯¸é ¹®Á¦¸¦
ÇÇÇÒ ¼ö ÀÖ´Ù.ÇÑ ¸®¼Ò½º¿¡ ´ëÇØ ¿©·¯ URLÀ» °¡Áö´Â À¥¼¹ö°¡ ÀÖ´Ù. º¸Åë (½ÇÁ¦ »ç¿ëÇÏ°í ¾Ë·ÁÁ®¾ß ÇÒ) ±âÁØÀÌ µÇ´Â URL°ú, ´ÜÃà ȤÀº ³»ºÎ ¿ëµµÀÇ URLÀÌ ÀÖ´Ù. »ç¿ëÀÚ°¡ ¿äû¿¡ ¾î¶² URLÀ» »ç¿ëÇÏ´øÁö ±âÁØÀÌ µÇ´Â URL¸¸À» º¸¿©Áà¾ß ÇÑ´Ù.
±âÁØÀÌ µÇÁö¾Ê´Â ¸ðµç URLÀ» ºê¶ó¿ìÀú°¡ ¾Ëµµ·Ï °íÄ¡±âÀ§ÇØ
¿ÜºÎ HTTP ¸®´ÙÀÌ·º¼ÇÇÑ´Ù. ¿¹¸¦ µé¾î ¾Æ·¡ ±ÔÄ¢Àº
/~user
¸¦ ±âÁØÀÌ µÇ´Â /u/user
·Î
´ëüÇÏ°í, /u/user
¸¶Áö¸·¿¡ ½½·¡½¬°¡ ¾ø´Ù¸é
Ãß°¡ÇÑ´Ù.
RewriteRule ^/~([^/]+)/?(.*) /u/$1/$2 [R] RewriteRule ^/([uge])/([^/]+)$ /$1/$2/ [R]
RewriteCond %{HTTP_HOST} !^fully\.qualified\.domain\.name [NC] RewriteCond %{HTTP_HOST} !^$ RewriteCond %{SERVER_PORT} !^80$ RewriteRule ^/(.*) http://fully.qualified.domain.name:%{SERVER_PORT}/$1 [L,R] RewriteCond %{HTTP_HOST} !^fully\.qualified\.domain\.name [NC] RewriteCond %{HTTP_HOST} !^$ RewriteRule ^/(.*) http://fully.qualified.domain.name/$1 [L,R]
DocumentRoot
¸¦ ¿Å±ä °æ¿ìÀ¥¼¹öÀÇ DocumentRoot
´Â º¸Åë URL
"/
"°ú Á÷Á¢ °ü·ÃÀÖ´Ù. ±×·¯³ª ÀÌ°÷¿¡ ¸ðµç
ÀÚ·á°¡ ÀÖÁö ¾Ê°í, ÀÚ·á°¡ ´Ù¸¥ ¿©·¯ °÷¿¡ Èð¾îÁ®ÀÖ´Â
°æ¿ì°¡ ÀÖ´Ù. ¿¹¸¦ µé¾î ÀÎÆ®¶ó³Ý »çÀÌÆ®¿¡ (¿ÜºÎ¸¦ À§ÇÑ
ȨÆäÀÌÁö) /e/www/
¿Í (ÀÎÆ®¶ó³ÝÀ» À§ÇÑ
ȨÆäÀÌÁö) /e/sww/
°¡ ÀÖ´Ù°í ÇÏÀÚ. ÀÌÁ¦
DocumentRoot
°¡
/e/www/
À̱⶧¹®¿¡, ¿äû¿¡¼ ÆäÀÌÁö¿¡
Æ÷ÇÔµÈ ±×¸² µîÀ» ÀÌ°÷¿¡¼ °¡Á®¿Í¾ß ÇÑ´Ù.
¿ì¸®´Â URL /
¸¦ /e/www/
·Î
¸®´ÙÀÌ·º¼Ç¸¸ ÇÏ¸é µÈ´Ù. »ç¼ÒÇØ º¸ÀÌÁö¸¸ ½ÇÁ¦·Î
mod_rewrite
¸¦ »ç¿ëÇؼ¸¸ °¡´ÉÇÏ´Ù.
(mod_alias
µîÀÌ Á¦°øÇÏ´Â) URL
Alias °°Àº ÀüÇüÀûÀÎ ¹æ¹ýÀº ¾ÕºÎºÐ¸¸
ã´Â´Ù. DocumentRoot
°¡
¸ðµç URLÀÇ ¾ÕºÎºÐÀ̱⶧¹®¿¡ ÀÌ ¹æ¹ýÀ» »ç¿ëÇÏ¿© ¸®´ÙÀÌ·º¼ÇÀ»
ÇÒ ¼ö ¾ø´Ù. mod_rewrite
¸¦ »ç¿ëÇϸé
ÁøÂ¥ °£´ÜÇÏ´Ù:
RewriteEngine on RewriteRule ^/$ /e/www/ [R]
µð·ºÅ丮¸¦ ÁöĪÇÏ´Â URLÀÇ ¸¶Áö¸· ½½·¡½¬ ¹®Á¦°¡
¾ø´Ù¸é ¸ðµç À¥°ü¸®Àڴ ȯȣÇÒ °ÍÀÌ´Ù. ½½·¡½¬°¡ ¾ø´Ù¸é,
Áï /~quux/foo/
´ë½Å /~quux/foo
¸¦
»ç¿ëÇÏ¸é ¼¹ö°¡ foo
¶ó´Â ÆÄÀÏÀ»
ã±â¶§¹®¿¡ ¿À·ù°¡ ¹ß»ýÇÑ´Ù. ÆÄÀÏÀÌ µð·ºÅ丮À̱⶧¹®¿¡
¹Þ¾ÆµéÀÌÁö ¾Ê´Â´Ù. ´ëºÎºÐÀÇ °æ¿ì º¸Åë ¼¹ö°¡ ÀÚµ¿À¸·Î
URLÀ» °íÄ¡Áö¸¸, °¡²û Á÷Á¢ ÇØÁà¾ß ÇÒ °æ¿ì°¡ ÀÖ´Ù. ¿¹¸¦
µé¾î, CGI ½ºÅ©¸³Æ® µîÀ¸·Î º¹ÀâÇÑ URL ÀçÀÛ¼ºÀ» ÇÑ ÈÄ¿¡
±×·¯ÇÏ´Ù.
ÀÌ ¹Ì¹¦ÇÑ ¹®Á¦ÀÇ ÇØ°á¹æ¹ýÀº ¼¹ö°¡ ÀÚµ¿À¸·Î ¸¶Áö¸·
½½·¡½¬¸¦ Ãß°¡ÇÏ´Â °ÍÀÌ´Ù. ºê¶ó¿ìÀú°¡ ³ª¸ÓÁö ±×¸² µîÀ»
¿Ã¹Ù·Î ¿äûÇÒ ¼ö ÀÖµµ·Ï, ¿ÜºÎ ¸®´ÙÀÌ·º¼ÇÀ» ÇØ¾ß ÇÑ´Ù.
³»ºÎ ¸®´ÙÀÌ·º¼ÇÀ» ÇÑ´Ù¸é µð·ºÅ丮 ÆäÀÌÁö¿¡¸¸ µ¿ÀÛÇÏ¿©
ÀÌ ÆäÀÌÁö°¡ »ó´ë URL·Î Æ÷ÇÔÇÏ´Â ±×¸²À» ºê¶ó¿ìÀú°¡
¿äûÇÒ¶§ ãÀ» ¼ö ¾ø´Ù. ¿¹¸¦ µé¾î, ¿ÜºÎ ¸®´ÙÀÌ·º¼ÇÀ»
»ç¿ëÇÏÁö ¾ÊÀ»¶§ /~quux/foo/index.html
¿¡¼
image.gif
¸¦ ¿äûÇϸé
/~quux/image.gif
¸¦ ¿äûÇÏ°Ô µÈ´Ù!
±×·¡¼ À̸¦ ÇØ°áÇϱâÀ§ÇØ ´ÙÀ½°ú °°ÀÌ ¼³Á¤ÇÑ´Ù:
RewriteEngine on RewriteBase /~quux/ RewriteRule ^foo$ foo/ [R]
Ȩµð·ºÅ丮ÀÇ ÃÖ»óÀ§ .htaccess
ÆÄÀÏ¿¡
´ÙÀ½°ú °°ÀÌ ¼³Á¤ÇÒ ¼öµµ ÀÖ´Ù. ±×·¯³ª ó¸®Çϴµ¥ ºÎ´ãÀÌ
µÈ´Ù.
RewriteEngine on RewriteBase /~quux/ RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^(.+[^/])$ $1/ [R]
ÀÎÆ®¶ó³Ý À¥¼¹ö±ºÀÇ ¸ðµç À¥¼¹ö¿¡ µ¿ÀÏÇÏ°í ÀÏ°üµÈ URL ±¸Á¶¸¦ ¸¸µé°í ½Í´Ù. Áï, ¸ðµç (Á¤ÀÇ»ó ¼¹ö¿¡ ¼ÓÇÏ¿© ¼¹ö¿¡ ÀÇÁ¸ÀûÀÎ!) URLÀ» ¼¹ö µ¶¸³ÀûÀ¸·Î ¸¸µç´Ù! À¥ À̸§°ø°£¿¡ ¼¹öµ¶¸³ÀûÀÎ µ¿ÀÏÇÑ ±¸Á¶¸¦ ºÎ¿©ÇØ¾ß ÇÑ´Ù: URLÀº ½ÇÁ¦ ¼¹ö¸¦ ÁöĪÇÏ¸é ¾ÈµÈ´Ù. ¼¹ö±ºÀÌ ÀÚµ¿À¸·Î ½ÇÁ¦ ¼¹ö·Î À¯µµÇÑ´Ù.
¸ÕÀú »ç¿ëÀÚ, ±×·ì, µ¶¸³Ã¼ÀÇ À§Ä¡ Á¤º¸¸¦ ÀúÀåÇÑ (ºÐ»êµÈ) ¿ÜºÎ¸Ê¿¡ ½ÇÁ¦ ¼¹ö Á¤º¸¸¦ ¾ò¾î¿Â´Ù. ¿ÜºÎ¸ÊÀº ´ÙÀ½°ú °°Àº Çü½ÄÀÌ´Ù
user1 server_of_user1 user2 server_of_user2 : :
¿ì¸®´Â ÀÌ Á¤º¸¸¦ °¢°¢ map.xxx-to-host
ÆÄÀÏ¿¡ ÀúÀåÇß´Ù. ´ÙÀ½À¸·Î ¸ðµç ¼¹ö¿¡¼ URLÀÌ ¼¹ö¿¡
¾ø´Ù¸é ´ÙÀ½°ú °°Àº URLÀ»,
/u/user/anypath /g/group/anypath /e/entity/anypath
´ÙÀ½°ú °°ÀÌ ¸®´ÙÀÌ·º¼ÇÇÑ´Ù
http://physical-host/u/user/anypath http://physical-host/g/group/anypath http://physical-host/e/entity/anypath
¾Æ·¡ ±ÔÄ¢Àº ¸ÊÆÄÀÏÀ» »ç¿ëÇÏ¿© ÀÌ ÀÛ¾÷À» ÇÑ´Ù (server0Àº ¸Ê¿¡ Ç׸ñÀÌ ¾ø´Â °æ¿ì »ç¿ëÇÒ ±âº»¼¹ö¶ó°í °¡Á¤ÇÑ´Ù):
RewriteEngine on RewriteMap user-to-host txt:/path/to/map.user-to-host RewriteMap group-to-host txt:/path/to/map.group-to-host RewriteMap entity-to-host txt:/path/to/map.entity-to-host RewriteRule ^/u/([^/]+)/?(.*) http://${user-to-host:$1|server0}/u/$1/$2 RewriteRule ^/g/([^/]+)/?(.*) http://${group-to-host:$1|server0}/g/$1/$2 RewriteRule ^/e/([^/]+)/?(.*) http://${entity-to-host:$1|server0}/e/$1/$2 RewriteRule ^/([uge])/([^/]+)/?$ /$1/$2/.www/ RewriteRule ^/([uge])/([^/]+)/([^.]+.+) /$1/$2/.www/$3\
¸¹Àº À¥°ü¸®ÀÚ´Â À¥¼¹öÀÇ ¸ðµç Ȩµð·ºÅ丮¸¦ ´Ù¸¥ À¥¼¹ö·Î ÀÌÀüÇÑ °æ¿ì ÇØ°áÃ¥À» ¹°¾îº»´Ù. ÀÌ ¹æ¹ýÀº ÀÌÀü ¼¹ö¸¦ ´ëüÇÒ »õ·Î¿î ¼¹ö¸¦ ±¸¼ºÇϴµ¥ ½Ã°£ÀÌ °É¸®´Â °æ¿ì¿¡ ÇÊ¿äÇÏ´Ù.
mod_rewrite
¸¦ »ç¿ëÇÏ¸é °£´ÜÇÏ´Ù.
ÀÌÀü À¥¼¹ö´Â ¸ðµç /~user/anypath
URLÀ»
http://newserver/~user/anypath
·Î
¸®´ÙÀÌ·º¼ÇÇÏ¸é µÈ´Ù.
RewriteEngine on RewriteRule ^/~(.+) http://newserver/~$1 [R,L]
»ç¿ëÀÚ°¡ ¼öõ¸íÀÎ »çÀÌÆ®´Â º¸Åë Ȩµð·ºÅ丮 ±¸Á¶¸¦
¸¸µç´Ù. Áï, ¿¹¸¦ µé¾î À̸§ÀÌ »ç¿ëÀÚ¸íÀÇ Ã¹¹ø° ¹®ÀÚÀÎ
ÇÏÀ§µð·ºÅ丮¿¡ Ȩµð·ºÅ丮¸¦ µÐ´Ù. ±×·¡¼,
/~foo/anypath
´Â
/home/f/foo/.www/anypath
ÀÌ°í,
/~bar/anypath
´Â
/home/b/bar/.www/anypath
ÀÌ´Ù.
¹°°áÇ¥½Ã°¡ ÀÖ´Â URLÀ» À§¿Í °°Àº ±¸Á¶·Î º¯È¯ÇϱâÀ§ÇØ ´ÙÀ½ ±ÔÄ¢À» »ç¿ëÇÑ´Ù.
RewriteEngine on RewriteRule ^/~(([a-z])[a-z0-9]+)(.*) /home/$2/$1/.www$3
ÀÌ ¿¹´Â ½Ç·Î ÇϵåÄÚ¾îÀûÀÌ´Ù: µð·ºÅ丮º°
RewriteRules
¸¦ ¸Å¿ì ¸¹ÀÌ »ç¿ëÇÏ¿© ÀÚ·á
ÀÚü´Â ±×´ë·Î µÐü·Î À¥¿¡ ÀڷḦ ÀÚ¿¬½º·´°Ô ºê¶ó¿ì¡Çϵµ·Ï
ÇÑ´Ù. ¹è°æ: ³ª´Â 1992³â ºÎÅÍ ÀÚÀ¯·Ó°Ô »ç¿ëÇÒ ¼ö ÀÖ´Â
À¯´Ð½º ¼ÒÇÁÆ®¿þ¾îµéÀ» net.sw¿¡
¸ð¾ÆµÎ°í ÀÖ¾ú´Ù. ÀÌ´Â ³»°¡ ÄÄÇ»ÅÍ°úÇÐÀ» °øºÎÇϸé¼
¿©·¯Çص¿¾È ¿©°¡½Ã°£¿¡ ½Ã½ºÅÛ °ü¸®ÀÚ¿Í ³×Æ®¿÷ °ü¸®ÀÚ¸¦
ÇؿԱ⶧¹®¿¡ ³» Ãë¹ÌÀÌÀÚ ÀÏÀÌ´Ù. ¸ÅÁÖ¸¶´Ù »õ·Î ¼ÒÇÁÆ®¿þ¾î°¡
Ãß°¡µÉ ¶§¸¶´Ù µð·ºÅ丮¸¦ ±í°Ô ¸¸µé¾î¿Ô´Ù:
drwxrwxr-x 2 netsw users 512 Aug 3 18:39 Audio/ drwxrwxr-x 2 netsw users 512 Jul 9 14:37 Benchmark/ drwxrwxr-x 12 netsw users 512 Jul 9 00:34 Crypto/ drwxrwxr-x 5 netsw users 512 Jul 9 00:41 Database/ drwxrwxr-x 4 netsw users 512 Jul 30 19:25 Dicts/ drwxrwxr-x 10 netsw users 512 Jul 9 01:54 Graphic/ drwxrwxr-x 5 netsw users 512 Jul 9 01:58 Hackers/ drwxrwxr-x 8 netsw users 512 Jul 9 03:19 InfoSys/ drwxrwxr-x 3 netsw users 512 Jul 9 03:21 Math/ drwxrwxr-x 3 netsw users 512 Jul 9 03:24 Misc/ drwxrwxr-x 9 netsw users 512 Aug 1 16:33 Network/ drwxrwxr-x 2 netsw users 512 Jul 9 05:53 Office/ drwxrwxr-x 7 netsw users 512 Jul 9 09:24 SoftEng/ drwxrwxr-x 7 netsw users 512 Jul 9 12:17 System/ drwxrwxr-x 12 netsw users 512 Aug 3 20:15 Typesetting/ drwxrwxr-x 10 netsw users 512 Jul 9 14:08 X11/
1996³â 7¿ù ÀÌ ÀúÀå¼Ò¸¦ ¸ÚÀÖ´Â À¥ ÀÎÅÍÆäÀ̽º¸¦ ÅëÇØ ¼¼»ó¿¡ °ø°³Çϱâ·Î °áÁ¤ÇÞ´Ù. "¸ÚÀÖ´Ù"´Â ¸»Àº, ÃÖ»óÀ§ µð·ºÅ丮¿¡ CGI ½ºÅ©¸³Æ®¸¦ µÎÁö ¾Ê°íµµ, ÀúÀå¼Ò °èÃþ±¸Á¶¸¦ Á÷Á¢ ºê¶ó¿ìÁúÇÏ±æ ¹Ù¶õ´Ù´Â ¶æÀÌ´Ù. ¿Ö? ÀúÀå¼Ò¸¦ ³ªÁß¿¡ FTP·Îµµ Á¢±ÙÇÒ ¼ö ÀÖµµ·Ï ¸¸µé ¿¹Á¤ÀÌ¿´±â¶§¹®¿¡ À¥À̳ª CGI¿Í °ü·ÃµÈ ³»¿ëÀ» °°ÀÌ µÎ±â ½È¾ú´Ù.
ÇØ°áÃ¥Àº µÎ ºÎºÐÀ¸·Î ³ª´¶´Ù: ¸ÕÀú µð·ºÅ丮 ¼öÁØ¿¡¼
ÇÊ¿äÇÑ ¸ðµç ÆäÀÌÁö¸¦ µ¿ÀûÀ¸·Î ¸¸µå´Â CGI ½ºÅ©¸³Æ®°¡
ÇÊ¿äÇÏ´Ù. ³ª´Â ÀÌ ½ºÅ©¸³Æ®µéÀ» ´ÙÀ½°ú °°ÀÌ
/e/netsw/.www/
¿¡ µÎ¾ú´Ù:
-rw-r--r-- 1 netsw users 1318 Aug 1 18:10 .wwwacl drwxr-xr-x 18 netsw users 512 Aug 5 15:51 DATA/ -rw-rw-rw- 1 netsw users 372982 Aug 5 16:35 LOGFILE -rw-r--r-- 1 netsw users 659 Aug 4 09:27 TODO -rw-r--r-- 1 netsw users 5697 Aug 1 18:01 netsw-about.html -rwxr-xr-x 1 netsw users 579 Aug 2 10:33 netsw-access.pl -rwxr-xr-x 1 netsw users 1532 Aug 1 17:35 netsw-changes.cgi -rwxr-xr-x 1 netsw users 2866 Aug 5 14:49 netsw-home.cgi drwxr-xr-x 2 netsw users 512 Jul 8 23:47 netsw-img/ -rwxr-xr-x 1 netsw users 24050 Aug 5 15:49 netsw-lsdir.cgi -rwxr-xr-x 1 netsw users 1589 Aug 3 18:43 netsw-search.cgi -rwxr-xr-x 1 netsw users 1885 Aug 1 17:41 netsw-tree.cgi -rw-r--r-- 1 netsw users 234 Jul 30 16:35 netsw-unlimit.lst
DATA/
ÇÏÀ§µð·ºÅ丮¿¡ À§¿¡¼ ¸»ÇÑ ÀúÀå¼Ò°¡
ÀÖ´Ù. ½ÇÁ¦ net.swÀÇ ³»¿ëÀº º¸Åë
rdist
¸¦ »ç¿ëÇÏ¿© ÀÚµ¿À¸·Î °¡Á®¿Â´Ù. µÎ¹ø°
ºÎºÐÀÌ ³²¾Ò´Ù: ¾î¶»°Ô ÀÌ µÎ ±¸Á¶¸¦ ÇϳªÀÇ ÀÚ¿¬½º·¯¿î
URL ±¸Á¶·Î ¿¬°áÇϴ°¡? »ç¿ëÀÚ¿¡°Ô DATA/
µð·ºÅ丮¸¦ °¨Ãß°í, URL¸¶´Ù ÀûÀýÇÑ CGI ½ºÅ©¸³Æ®¸¦ ½ÇÇàÇÏ°í
½Í´Ù. ÇØ°áÃ¥Àº ´ÙÀ½°ú °°´Ù: ¸ÕÀú ¼¹öÀÇ DocumentRoot
¿¡¼ °ø°³µÈ
URL /net.sw/
¸¦ ³»ºÎ °æ·Î /e/netsw
·Î
ÀçÀÛ¼ºÇϱâÀ§ÇØ µð·ºÅ丮º° ¼³Á¤ÆÄÀÏ¿¡ ´ÙÀ½°ú °°ÀÌ ¼³Á¤ÇÑ´Ù:
RewriteRule ^net.sw$ net.sw/ [R] RewriteRule ^net.sw/(.*)$ e/netsw/$1
ù¹ø° ±ÔÄ¢Àº ¸¶Áö¸·¿¡ ½½·¡½¬°¡ ¾ø´Â ¿äûÀ» À§Çؼ
»ç¿ëÇß´Ù! µÎ¹ø° ±ÔÄ¢ÀÌ ½ÇÁ¦ ÀÛ¾÷À» ÇÑ´Ù. ±×¸®°í µð·ºÅ丮º°
¼³Á¤ÆÄÀÏ /e/netsw/.www/.wwwacl
¿¡ °áÁ¤ÀûÀÎ
¼³Á¤ÀÌ ³ª¿Â´Ù:
Options ExecCGI FollowSymLinks Includes MultiViews RewriteEngine on # ¾Õ ºÎºÐÀÌ /net.sw/ ·Î Á¢±ÙÇÑ´Ù RewriteBase /net.sw/ # ¸ÕÀú ÃÖ»óÀ§ µð·ºÅ丮¸¦ # cgi ½ºÅ©¸³Æ®·Î ÀçÀÛ¼ºÇÑ´Ù RewriteRule ^$ netsw-home.cgi [L] RewriteRule ^index\.html$ netsw-home.cgi [L] # ºê¶ó¿ìÀú°¡ µð·ºÅ丮º° ÆäÀÌÁö¸¦ ¿äûÇÑ °æ¿ì # ÇÏÀ§µð·ºÅ丮¸¦ ÃßÃâÇÑ´Ù RewriteRule ^.+/(netsw-[^/]+/.+)$ $1 [L] # ÀÌÁ¦ ÀçÀÛ¼ºÀ» ¸¶Ä£´Ù RewriteRule ^netsw-home\.cgi.* - [L] RewriteRule ^netsw-changes\.cgi.* - [L] RewriteRule ^netsw-search\.cgi.* - [L] RewriteRule ^netsw-tree\.cgi$ - [L] RewriteRule ^netsw-about\.html$ - [L] RewriteRule ^netsw-img/.*$ - [L] # ´Ù¸¥ cgi ½ºÅ©¸³Æ®°¡ ó¸®ÇÒ # ÇÏÀ§µð·ºÅ丮°¡ ³²¾Ò´Ù RewriteRule !^netsw-lsdir\.cgi.* - [C] RewriteRule (.*) netsw-lsdir.cgi/$1
Çؼ®À» À§ÇÑ ÈùÆ®:
-
')°¡
¾ø°í L
(last) Ç÷¡±×°¡ ÀÖÀ½À» ÁÖ¸ñÇ϶ó!
(not) ¹®ÀÚ¿Í C
(chain) Ç÷¡±×¸¦ ÁÖ¸ñÇ϶ómod_imagemap
À¸·Î»ç¶÷µéÀº NCSA À¥¼¹ö¿¡¼ Çö´ëÀûÀÎ ¾ÆÆÄÄ¡ À¥¼¹ö·Î
ÀÚ¿¬½º·´°Ô ¿Å°Ü°¡±æ ¹Ù¶õ´Ù. ±×·¡¼ ¿À·¡µÈ NCSA
imagemap
ÇÁ·Î±×·¥À» »ç¿ëÇÑ ÆäÀÌÁö¸¦ Çö´ëÀûÀÎ
¾ÆÆÄÄ¡ mod_imagemap
·Î ó¸®ÇÏ±æ ¹Ù¶õ´Ù.
¹®Á¦´Â imagemap
ÇÁ·Î±×·¥À»
/cgi-bin/imagemap/path/to/page.map
°ú
°°ÀÌ ÂüÁ¶ÇÏ´Â ÇÏÀÌÆÛ¸µÅ©°¡ ¸¹´Ù´Â °ÍÀÌ´Ù. ¾ÆÆÄÄ¡´Â
/path/to/page.map
°ú °°Àº ¿äûÀ» ¹Þ¾Æ¾ß
ÇÑ´Ù.
¸ðµç ¿äû¿¡¼ ¾ÕºÎºÐÀ» µ¿ÀûÀ¸·Î Á¦°ÅÇÏ´Â Àü¿ª ±ÔÄ¢À» »ç¿ëÇÑ´Ù:
RewriteEngine on RewriteRule ^/cgi-bin/imagemap(.*) $1 [PT]
°¡²û À¥¼¹ö°¡ ¿©·¯ µð·ºÅ丮¿¡¼ ÆÄÀÏÀ» ã¾Æ¾ß ÇÒ ¶§°¡ ÀÖ´Ù. ÀÌ °æ¿ì MultiViews³ª ´Ù¸¥ ¹æ¹ýÀº µµ¿òÀÌ ¾ÈµÈ´Ù.
¿©·¯ µð·ºÅ丮¿¡¼ ÆÄÀÏÀ» ã´Â ±ÔÄ¢À» Á÷Á¢ ÇÁ·Î±×·¥ÇÑ´Ù.
RewriteEngine on # ¸ÕÀú custom/¿¡¼ ã±æ ½ÃµµÇÏ°í... # ...ãÀ¸¸é ³¡! RewriteCond /your/docroot/dir1/%{REQUEST_FILENAME} -f RewriteRule ^(.+) /your/docroot/dir1/$1 [L] # µÎ¹ø°·Î pub/¿¡¼ ã±æ ½ÃµµÇÑ´Ù... # ...ãÀ¸¸é ³¡! RewriteCond /your/docroot/dir2/%{REQUEST_FILENAME} -f RewriteRule ^(.+) /your/docroot/dir2/$1 [L] # ¸øãÀ¸¸é ´Ù¸¥ Alias³ª ScriptAlias Áö½Ã¾î µîÀ¸·Î ÁøÇàÇÑ´Ù. RewriteRule ^(.+) - [PT]
¿äûµé°£¿¡ »óÅÂÁ¤º¸¸¦ À¯ÁöÇϱâÀ§ÇØ URL¿¡ Á¤º¸¸¦ ÀÎÄÚµùÇÏ´Â ¹æ¹ýµµ ÀÖ´Ù. ±×·¯³ª ´ÜÁö ÀÌ Á¤º¸¸¦ Á¦°ÅÇϱâÀ§ÇØ ¸ðµç ÆäÀÌÁö¿¡ CGI wrapper¸¦ »ç¿ëÇÏ°í ½ÍÁö ¾Ê´Ù.
ÀçÀÛ¼º ±ÔÄ¢À» »ç¿ëÇÏ¿© »óÅÂÁ¤º¸¸¦ ÃßÃâÇÏ°í, ÃßÃâÇÑ
Á¤º¸¸¦ ³ªÁß¿¡ XSSI³ª CGI¿¡¼ »ç¿ëÇϱâÀ§ÇØ È¯°æº¯¼ö¿¡
ÀúÀåÇÑ´Ù. ±×·¡¼ URL /foo/S=java/bar/
´Â
/foo/bar/
·Î º¯È¯µÇ°í STATUS
¶ó´Â
ȯ°æº¯¼ö °ªÀ» "java"·Î ¼³Á¤ÇÑ´Ù.
RewriteEngine on RewriteRule ^(.*)/S=([^/]+)/(.*) $1/$3 [E=STATUS:$2]
°¡»óÈ£½ºÆ®¸¦ »ç¿ëÇÏÁö ¾Ê°í °°Àº ÄÄÇ»ÅÍ·Î DNS A
·¹Äڵ带 ¼³Á¤ÇÏ¿©
www.username.host.domain.com
À»
»ç¿ëÀÚÀÇ È¨ÆäÀÌÁö·Î Á¦°øÇÏ°í ½Í´Ù.
HTTP/1.0 ¿äûÀÇ °æ¿ì ¹æ¹ýÀÌ ¾øÁö¸¸, Host: HTTP
Çì´õ¸¦ Æ÷ÇÔÇÑ HTTP/1.1 ¿äûÀº ´ÙÀ½ ±ÔÄ¢À» »ç¿ëÇÏ¿©
³»ºÎÀûÀ¸·Î http://www.username.host.com/anypath
¸¦
/home/username/anypath
·Î ÀçÀÛ¼ºÇÒ ¼ö
ÀÖ´Ù:
RewriteEngine on RewriteCond %{HTTP_HOST} ^www\.[^.]+\.host\.com$ RewriteRule ^(.+) %{HTTP_HOST}$1 [C] RewriteRule ^www\.([^.]+)\.host\.com(.*) /home/$1$2
Áö¿ª µµ¸ÞÀÎ ourdomain.com
¹Û¿¡¼ ¿äûÀÌ
µé¾î¿À¸é Ȩµð·ºÅ丮 URLÀ» ´Ù¸¥ À¥¼¹ö
www.somewhere.com
À¸·Î ¸®´Ù¸®·º¼ÇÇϱæ
¹Ù¶õ´Ù. Á¾Á¾ °¡»óÈ£½ºÆ® »ç¿ëÀå¼Ò¿¡¼ »ç¿ëÇÑ´Ù.
ÀçÀÛ¼º Á¶°ÇÀ» »ç¿ëÇÏ¸é µÈ´Ù:
RewriteEngine on RewriteCond %{REMOTE_HOST} !^.+\.ourdomain\.com$ RewriteRule ^(/~.+) http://www.somewhere.com/$1 [R,L]
URL ÀçÀÛ¼º¿¡ ´ëÇؼ À¥¼¹ö A¿¡ ÇØ´ç ÆÄÀÏÀÌ ¾ø´Â
°æ¿ì À¥¼¹ö B·Î ¿äûÀ» ¸®´ÙÀÌ·º¼ÇÇÏ´Â ¹æ¹ýÀ» ÀÚÁÖ
¹°¾îº»´Ù. º¸Åë Perl·Î ÀÛ¼ºÇÑ ErrorDocument
CGI ½ºÅ©¸³Æ®¸¦
»ç¿ëÇÏÁö¸¸, mod_rewrite
¸¦ »ç¿ëÇÏ´Â
¹æ¹ýµµ ÀÖ´Ù. ±×·¯³ª ¼º´ÉÀº ErrorDocument
CGI ½ºÅ©¸³Æ®º¸´Ù
¶³¾îÁüÀ» ¸í½ÉÇ϶ó!
ù¹ø° ¹æ¹ýÀº ºü¸£Áö¸¸ À¯¿¬¼ºÀÌ ¶³¾îÁö°í ¿ÏÀüÇÏÁö ¾Ê´Ù:
RewriteEngine on RewriteCond /your/docroot/%{REQUEST_FILENAME} !-f RewriteRule ^(.+) http://webserverB.dom/$1
ÀÌ ¹æ¹ýÀÇ ´ÜÁ¡Àº DocumentRoot
¾È¿¡ ÀÖ´Â ÆäÀÌÁö¸¸
°¡´ÉÇÏ´Ù´Â Á¡ÀÌ´Ù. (¿¹¸¦ µé¾î Ȩµð·ºÅ丮 µîÀ» À§ÇØ)
Á¶°ÇÀ» Ãß°¡ÇÒ ¼ö ÀÖÁö¸¸, ´õ ÁÁÀº ¹æ¹ýÀÌ ÀÖ´Ù:
RewriteEngine on RewriteCond %{REQUEST_URI} !-U RewriteRule ^(.+) http://webserverB.dom/$1
mod_rewrite
ÀÇ URL Àü¹æÂüÁ¶(look-ahead)¸¦
»ç¿ëÇÑ´Ù. ±×·¡¼ ¸ðµç URL¿¡ µ¿ÀÛÇÏ°í ¾ÈÀüÇÏ´Ù. ±×·¯³ª
¸ðµç ¿äû¸¶´Ù ³»ºÎ ÇÏÀ§¿äûÀ» Çѹø ´õ Çϱ⶧¹®¿¡ À¥¼¹ö
¼º´É¿¡ ¾Ç¿µÇâÀ» ÁØ´Ù. ±×·¡¼ °·ÂÇÑ CPU¿¡¼ À¥¼¹ö¸¦
½ÇÇàÇÑ´Ù¸é »ç¿ëÇ϶ó. ÄÄÇ»ÅÍ°¡ ´À¸®´Ù¸é ù¹ø° ¹æ¹ýÀ̳ª
´õ ³ªÀº ErrorDocument
CGI ½ºÅ©¸³Æ®¸¦ »ç¿ëÇ϶ó.
°¡²û ¸®´ÙÀÌ·º¼ÇÇÏ´Â URLÀ» ´õ Á¶ÀýÇÒ ÇÊ¿ä°¡ ÀÖ´Ù.
¾ÆÆÄÄ¡ ³»ºÎ URL escape ÇÔ¼ö´Â "url#anchor
"
°°Àº URLÀÇ anchorµµ escapeÇÑ´Ù. ¾ÆÆÄÄ¡ÀÇ
uri_escape()
ÇÔ¼ö´Â ¿ì¹°Á¤ÀÚ(#)µµ °°ÀÌ
escapeÇϹǷΠ»ç¿ëÇÒ ¼ö ¾ø´Ù. ±×·¯¸é ¾î¶»°Ô ÀÌ·± URL·Î
¸®´ÙÀÌ·º¼ÇÇÒ ¼ö ÀÖ³ª?
Á÷Á¢ ¸®´ÙÀÌ·º¼ÇÇÏ´Â NPH-CGI ½ºÅ©¸³Æ®¸¦ »ç¿ëÇÑ ÇØ°áÃ¥ÀÌ
ÇÊ¿äÇÏ´Ù. escape¸¦ ÇÏÁö ¾Ê±â¶§¹®ÀÌ´Ù (NPH=non-parseable
headers). ¸ÕÀú ´ÙÀ½ ¼¹ö¼³Á¤À» ÇÏ¿© (ÀçÀÛ¼º ±ÔÄ¢ÀÇ
³¡ºÎºÐ¿¡ »ç¿ëÇØ¾ß ÇÑ´Ù) »õ·Î¿î URL scheme
xredirect:
¸¦ µµÀÔÇÑ´Ù:
RewriteRule ^xredirect:(.+) /path/to/nph-xredirect.cgi/$1 \ [T=application/x-httpd-cgi,L]
±×·¯¸é xredirect:
·Î ½ÃÀÛÇÏ´Â ¸ðµç URLÀº
nph-xredirect.cgi
ÇÁ·Î±×·¥À» ÅëÇÏ°Ô µÈ´Ù.
ÇÁ·Î±×·¥Àº ´ÙÀ½°ú °°´Ù:
#!/path/to/perl ## ## nph-xredirect.cgi -- NPH/CGI script for extended redirects ## Copyright (c) 1997 Ralf S. Engelschall, All Rights Reserved. ## $| = 1; $url = $ENV{'PATH_INFO'}; print "HTTP/1.0 302 Moved Temporarily\n"; print "Server: $ENV{'SERVER_SOFTWARE'}\n"; print "Location: $url\n"; print "Content-type: text/html\n"; print "\n"; print "<html>\n"; print "<head>\n"; print "<title>302 Moved Temporarily (EXTENDED)</title>\n"; print "</head>\n"; print "<body>\n"; print "<h1>Moved Temporarily (EXTENDED)</h1>\n"; print "The document has moved <a HREF=\"$url\">here</a>.<p>\n"; print "</body>\n"; print "</html>\n"; ##EOF##
±×·¯¸é mod_rewrite
°¡ Á÷Á¢ ¹ÞÁö¸øÇÏ´Â
¸ðµç URL schemeÀ¸·Î ¸®´ÙÀÌ·º¼ÇÇÒ ¼ö ÀÖ´Ù. ¿¹¸¦ µé¾î,
´ÙÀ½°ú °°ÀÌ news:newsgroup
À¸·Î ¸®´ÙÀÌ·º¼ÇÇÒ
¼ö ÀÖ´Ù
RewriteRule ^anyurl xredirect:news:newsgroup
xredirect:
¸¦ ¸¶Áö¸·¿¡ È®ÀåÇØ¾ß Çϱ⶧¹®¿¡
±ÔÄ¢¿¡ [R]
À̳ª [R,L]
À» »ç¿ëÇϸé
¾ÈµÈ´Ù.http://www.perl.com/CPAN¿¡
ÀÖ´Â ´ë´ÜÇÑ CPAN (Comprehensive Perl Archive Network)À»
¾Æ´Â°¡? ÀÌ ÁÖ¼Ò´Â ¼¼°è¿¡ Èð¾îÁø ¿©·¯ CPAN ¹Ì·¯ FTP
¼¹öÁß Å¬¶óÀ̾ðÆ®¿¡ °¡±îÀÌ ÀÖ´Â ¼¹ö·Î ¸®´ÙÀÌ·º¼ÇÇÑ´Ù.
À̸¦ FTP Á¢±Ù Áß°è ¼ºñ½º¶ó°í ÇÑ´Ù. CPANÀº CGI ½ºÅ©¸³Æ®¸¦
»ç¿ëÇÏÁö¸¸, mod_rewrite
¸¦ »ç¿ëÇÏ¿©
ºñ½ÁÇÏ°Ô ¸¸µé ¼ö ÀÖÀ»±î?
¸ÕÀú mod_rewrite
3.0.0 ¹öÀüºÎÅÍ
¸®´ÙÀÌ·º¼Ç¿¡ "ftp:
" schemeÀ» »ç¿ëÇÒ ¼ö
ÀÖ´Ù. ´ÙÀ½À¸·Î Ŭ¶óÀ̾ðÆ®ÀÇ ÃÖ»óÀ§ µµ¸ÞÀÎÀ» RewriteMap
°ú °°ÀÌ
»ç¿ëÇÏ¿© À§Ä¡¸¦ ÃßÁ¤ÇÒ ¼ö ÀÖ´Ù. º¹ÀâÈ÷ ¿«ÀÎ ±ÔÄ¢¿¡¼
ÃÖ»óÀ§ µµ¸ÞÀÎÀ» Áß°è¸ÊÀÇ Å°·Î »ç¿ëÇÑ´Ù.
RewriteEngine on RewriteMap multiplex txt:/path/to/map.cxan RewriteRule ^/CxAN/(.*) %{REMOTE_HOST}::$1 [C] RewriteRule ^.+\.([a-zA-Z]+)::(.*)$ ${multiplex:$1|ftp.default.dom}$2 [R,L]
## ## map.cxan -- Multiplexing Map for CxAN ## de ftp://ftp.cxan.de/CxAN/ uk ftp://ftp.cxan.uk/CxAN/ com ftp://ftp.cxan.com/CxAN/ : ##EOF##
½Ã°£¿¡ µû¶ó ´Ù¸¥ ³»¿ëÀ» ¼ºñ½ºÇÏ´Â °æ¿ì ¸¹Àº À¥°ü¸®ÀÚ´Â
Àá½Ã Ưº°ÇÑ ÆäÀÌÁö·Î ¸®´ÙÀÌ·º¼ÇÇϱâÀ§ÇØ CGI ½ºÅ©¸³Æ®¸¦
»ç¿ëÇÑ´Ù. mod_rewrite
·Î´Â ¾î¶»°Ô
ÇÒ ¼ö Àִ°¡?
ÀçÀÛ¼º Á¶°Ç¿¡¼ »ç¿ëÇÒ ¼ö ÀÖ´Â ¿©·¯ TIME_xxx
º¯¼ö°¡ ÀÖ´Ù. º¯¼ö¿Í Ưº°ÇÑ »çÀü¼ø¼ ºñ±³
<STRING
, >STRING
,
=STRING
À» »ç¿ëÇÏ¿© ½Ã°£¿¡ µû¶ó ¸®´ÙÀÌ·º¼ÇÇÒ
¼ö ÀÖ´Ù:
RewriteEngine on RewriteCond %{TIME_HOUR}%{TIME_MIN} >0700 RewriteCond %{TIME_HOUR}%{TIME_MIN} <1900 RewriteRule ^foo\.html$ foo.day.html RewriteRule ^foo\.html$ foo.night.html
URL foo.html
À» ¿äûÇϸé
07:00-19:00
µ¿¾È foo.day.html
³»¿ëÀ» ¼ºñ½ºÇÏ°í, ³ª¸ÓÁö ½Ã°£ µ¿¾È
foo.night.html
³»¿ëÀ» ¼ºñ½ºÇÑ´Ù. ȨÆäÀÌÁö¿¡¼
»ç¿ëÇϱâ ÁÁÀº ±â´ÉÀÌ´Ù...
¿©·¯ .html
ÆÄÀÏÀ» .phtml
·Î
º¯È¯ÇÏ´Â µî document.YYYY
¸¦
document.XXXX
·Î ÀÌÀüÇÑÈÄ ¿ªÈ£È¯(backward
compatibility) URLÀ» (°¡»óÀûÀ¸·Î Á¸ÀçÇÏ°Ô) ¸¸µé ¼ö
ÀÖ³ª?
À̸§À» ±âº»À̸§À¸·Î ÀçÀÛ¼ºÇÑÈÄ »õ·Î¿î È®ÀåÀÚ¸¦ °¡Áø ÆÄÀÏÀÌ ÀÖ´ÂÁö °Ë»çÇÑ´Ù. ÀÖ´Ù¸é ±× ÆÄÀϸíÀ» »ç¿ëÇÏ°í, ¾øÀ¸¸é URLÀ» ¿ø·¡ »óÅ·ΠÀçÀÛ¼ºÇÑ´Ù.
# ¹®¼.html ÀÌ ¾ø°í # ¹®¼.phtml ¸¸ ÀÖ´Â °æ¿ì # ¹®¼.html À» ¹®¼.phtml ·Î # ÀçÀÛ¼ºÇÏ´Â ¿ªÈ£È¯ ±ÔÄ¢ RewriteEngine on RewriteBase /~quux/ # ±âº»À̸§À» ã°í, ã¾Ò´Ù´Â »ç½ÇÀ» ±â¾ïÇÑ´Ù RewriteRule ^(.*)\.html$ $1 [C,E=WasHTML:yes] # ÆÄÀÏÀÌ ÀÖ´Ù¸é ¹®¼.phtml ·Î ÀçÀÛ¼ºÇÑ´Ù RewriteCond %{REQUEST_FILENAME}.phtml -f RewriteRule ^(.*)$ $1.phtml [S=1] # ¾Æ´Ï¸é ¾Õ¿¡¼ ãÀº ±âº»À̸§À» µÇµ¹¸°´Ù RewriteCond %{ENV:WasHTML} ^yes$ RewriteRule ^(.*)$ $1.html
ÃÖ±Ù foo.html
À» bar.html
·Î
º¯°æÇÏ°í ¿ªÈ£È¯¼ºÀ» À§ÇØ ÀÌÀü URLÀ» °è¼Ó Á¦°øÇÏ°í
½Í´Ù°í °¡Á¤ÇÏÀÚ. »ç¿ëÀÚ´Â ÀÌÀü URLÀÌ º¯°æµÇ¾ú´Ù´Â
»ç½ÇÀ» ´«Ä¡Ã¤Áö ¸øÇÑ´Ù.
´ÙÀ½ ±ÔÄ¢À¸·Î ÀÌÀü URLÀ» ³»ºÎÀûÀ¸·Î »õ·Î¿î URL·Î ÀçÀÛ¼ºÇÑ´Ù:
RewriteEngine on RewriteBase /~quux/ RewriteRule ^foo\.html$ bar.html
´Ù½Ã foo.html
À» bar.html
·Î
º¯°æÇÏ°í ¿ªÈ£È¯¼ºÀ» À§ÇØ ÀÌÀü URLÀ» °è¼Ó Á¦°øÇÏ°í
½Í´Ù°í °¡Á¤ÇÏÀÚ. ±×·¯³ª ÀÌÁ¦´Â ÀÌÀü URLÀ» »ç¿ëÇϸé
»ç¿ëÀÚ¿¡°Ô »õ·Î¿î URLÀ» ÈùÆ®·Î ¾Ë·ÁÁØ´Ù. Áï, ºê¶ó¿ìÀú
ÁÖ¼ÒâÀÌ º¯ÇÑ´Ù.
»õ·Î¿î URL·Î HTTP ¸®´ÙÀÌ·º¼ÇÇÏ´Ù. ±×·¯¸é ºê¶ó¿ìÀú°¡ »õ·Î¿î URL¸¦ º¸ÀÌ°í º¯°æ»ç½ÇÀ» »ç¿ëÀÚ°¡ ¾Ë°ÔµÈ´Ù:
RewriteEngine on RewriteBase /~quux/ RewriteRule ^foo\.html$ bar.html [R]
ÃÖ¼ÒÇÑ Áß¿äÇÑ ÃÖ»óÀ§ ÆäÀÌÁö´Â ºê¶ó¿ìÀú¿¡ ÃÖÀûÈµÈ ³»¿ëÀ¸·Î ¼ºñ½ºÇؾßÇÒ °æ¿ì°¡ ÀÖ´Ù. Áï, ÃֽŠNetscape ºê¶ó¿ìÀú¿¡°Ô´Â ÃÖ»óÀÇ ¹öÀüÀ», Lynx ºê¶ó¿ìÀú¿¡°Ô´Â ÃÖÀú ¹öÀüÀ», ³ª¸ÓÁö ºê¶ó¿ìÀú¿¡´Â Æò±ÕÀûÀÎ ¹öÀüÀ» Á¦°øÇÑ´Ù.
ºê¶ó¿ìÀú°¡ ³»¿ëÇù»óÀ» À§ÇØ ÀÚ½ÅÀÇ Á¾·ù¿¡ ´ëÇÑ Á¤º¸¸¦
Á¦°øÇÏÁö ¾Ê±â¶§¹®¿¡ ³»¿ëÇù»óÀ» »ç¿ëÇÒ ¼ö ¾ø´Ù. ´ë½Å
HTTP "User-Agent" Çì´õ¸¦ »ç¿ëÇÑ´Ù. ´ÙÀ½ ±ÔÄ¢Àº HTTP
"User-Agent" Çì´õ°¡ "Mozilla/3"À¸·Î ½ÃÀÛÇϸé
foo.html
ÆäÀÌÁö¸¦ foo.NS.html
·Î
ÀçÀÛ¼ºÇÏ°í ÀçÀÛ¼ºÀ» Áß´ÜÇÑ´Ù. ºê¶ó¿ìÀú°¡ "Lynx"³ª
"Mozilla" ¹öÀü 1 ȤÀº 2¶ó¸é URLÀº
foo.20.html
ÀÌ µÈ´Ù. ³ª¸ÓÁö ºê¶ó¿ìÀú´Â
foo.32.html
ÆäÀÌÁö¸¦ ¹Þ´Â´Ù. ¾Æ·¡ ±ÔÄ¢ÀÌ
ÀÌ ÀÛ¾÷À» ÇÑ´Ù:
RewriteCond %{HTTP_USER_AGENT} ^Mozilla/3.* RewriteRule ^foo\.html$ foo.NS.html [L] RewriteCond %{HTTP_USER_AGENT} ^Lynx/.* [OR] RewriteCond %{HTTP_USER_AGENT} ^Mozilla/[12].* RewriteRule ^foo\.html$ foo.20.html [L] RewriteRule ^foo\.html$ foo.32.html [L]
¿ÜºÎ È£½ºÆ®¿¡ ¿ì¸® »çÀÌÆ®·Î °¡Á®¿À°í ½ÍÀº ÁÁÀº
À¥ÆäÀÌÁö°¡ ÀÖ´Ù°í °¡Á¤ÇÏÀÚ. FTP ¼¹öÀÇ °æ¿ì Á÷Á¢ ¿ÜºÎ
ÀÚ·áÀÇ Ãֽź¹»çº»À» À¯ÁöÇÏ´Â mirror
ÇÁ·Î±×·¥À»
»ç¿ëÇÒ ¼ö ÀÖ°í, À¥¼¹ö¶ó¸é HTTP·Î ºñ½ÁÇÑ ÀÛ¾÷À» ÇÏ´Â
webcopy
ÇÁ·Î±×·¥À» »ç¿ëÇÒ ¼ö ÀÖ´Ù. ±×·¯³ª
µÎ ¹æ¹ý ¸ðµÎ ´ÜÁ¡ÀÌ ÀÖ´Ù: º¹»çº»Àº °¡²û¾¿ ÇÁ·Î±×·¥À»
½ÇÇàÇØÁÙ ¶§¸¸ ÃÖ½ÅÆÇÀ¸·Î À¯ÁöµÈ´Ù. Á÷Á¢ ±¸¼ºÇؾßÇÏ´Â
Á¤ÀûÀÎ ¹Ì·¯°¡ ¾Æ´Ï¶ó¸é ÁÁ°Ú´Ù. ´ë½Å (¿ÜºÎ È£½ºÆ®¿¡¼
ÀÚ·á°¡ °»½ÅµÇ¸é) ÇÊ¿äÇÒ¶§ ÀÚµ¿À¸·Î ÀڷḦ °»½ÅÇÏ´Â
µ¿Àû ¹Ì·¯°¡ ÇÊ¿äÇÏ´Ù.
À̸¦ À§ÇØ Proxy Throughput ±â´ÉÀ» (Ç÷¡±×
[P]
) »ç¿ëÇÏ¿© ¿ÜºÎ À¥ÆäÀÌÁö ȤÀº ¿ÜºÎ
À¥°ø°£ Àüü¸¦ ¿ì¸® À̸§°ø°£À¸·Î ´ëÀÀÇÑ´Ù:
RewriteEngine on RewriteBase /~quux/ RewriteRule ^hotsheet/(.*)$ http://www.tstimpreso.com/hotsheet/$1 [P]
RewriteEngine on RewriteBase /~quux/ RewriteRule ^usa-news\.html$ http://www.quux-corp.com/news/index.html [P]
RewriteEngine on RewriteCond /mirror/of/remotesite/$1 -U RewriteRule ^http://www\.remotesite\.com/(.*)$ /mirror/of/remotesite/$1
½ÇÁ¦ ÀڷḦ ¹æȺ®ÀÌ º¸È£ÇÏ´Â (³»ºÎ) ÀÎÆ®¶ó³Ý À¥¼¹ö¿¡
(www2.quux-corp.dom
) ÀúÀåÇϸé¼, ±â¾÷ÀÇ
(¿ÜºÎ) ÀÎÅÍ³Ý À¥¼¹ö¸¦ (www.quux-corp.dom
)
½ÇÇàÇÏ´Â °Íó·³ º¸ÀÌ°Ô ÇÑ´Ù. ¿ÜºÎ À¥¼¹ö´Â ¿äûÇÑ
ÀڷḦ ³»ºÎ À¥¼¹ö¿¡¼ °¡Á®¿Â´Ù.
¸ÕÀú ¹æȺ®ÀÌ ³»ºÎ À¥¼¹ö¸¦ º¸È£ÇÏ°í ¿ÜºÎ À¥¼¹ö¸¸ÀÌ ³»ºÎ À¥¼¹ö¿¡¼ ÀڷḦ ¾òÀ» ¼ö ÀÖ°Ô ÇÑ´Ù. ´ÙÀ½°ú °°ÀÌ ÆÐŶÇÊÅ͸µ ¹æȺ®À» ¼³Á¤ÇÑ´Ù:
ALLOW Host www.quux-corp.dom Port >1024 --> Host www2.quux-corp.dom Port 80 DENY Host * Port * --> Host www2.quux-corp.dom Port 80
½ÇÁ¦ ¼³Á¤¹®¹ý¿¡ ¾Ë¸Â°Ô °íÃĶó. ¾ø´Â ÀڷḦ ³»ºÎÀûÀ¸·Î
proxy throughput ±â´ÉÀ» ÅëÇØ ¿äûÇÏ´Â
mod_rewrite
±ÔÄ¢À» ÀÛ¼ºÇÑ´Ù:
RewriteRule ^/~([^/]+)/?(.*) /home/$1/.www/$2 RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^/home/([^/]+)/.www/?(.*) http://www2.quux-corp.dom/~$1/pub/$2 [P]
www.foo.com
ÀÇ Åë½Å·®À»
www[0-5].foo.com
(ÃÑ ¼¹ö 6´ë)À¸·Î ºÐ»êÇÏ°í
½Í´Ù. ¾î¶»°Ô Çϴ°¡?
¸Å¿ì ´Ù¾çÇÑ ¹æ¹ýÀ¸·Î ÀÌ ¹®Á¦¸¦ ÇØ°áÇÒ ¼ö ÀÖ´Ù.
¸ÕÀú DNS¸¦ »ç¿ëÇÑ Àß ¾Ë·ÁÁø ¹æ¹ýÀ» ¼³¸íÇÏ°í,
mod_rewrite
¸¦ »ç¿ëÇÏ´Â °æ¿ì¸¦ »ìÆ캸ÀÚ:
°¡Àå °£´ÜÇÑ ·Îµå¹ë·±½Ì ¹æ¹ýÀº BIND
ÀÇ
DNS round-robin ¹æ½ÄÀ» »ç¿ëÇÏ´Â °ÍÀÌ´Ù. ´ÙÀ½°ú
°°ÀÌ DNS A(address) ·¹Äڵ忡
www[0-9].foo.com
À» ¼³Á¤ÇÑ´Ù.
www0 IN A 1.2.3.1 www1 IN A 1.2.3.2 www2 IN A 1.2.3.3 www3 IN A 1.2.3.4 www4 IN A 1.2.3.5 www5 IN A 1.2.3.6
±×¸®°í ´ÙÀ½ Ç׸ñÀ» Ãß°¡ÇÑ´Ù:
www IN CNAME www0.foo.com. IN CNAME www1.foo.com. IN CNAME www2.foo.com. IN CNAME www3.foo.com. IN CNAME www4.foo.com. IN CNAME www5.foo.com. IN CNAME www6.foo.com.
À߸øµÈ °Íó·³ º¸ÀÌÁö¸¸, ½ÇÁ¦·Î BIND
ÀÇ
ÀǵµµÈ ±â´ÉÀÌ´Ù. ÀÌÁ¦ www.foo.com
À»
ãÀ¸¸é, BIND
´Â ¸Å¹ø ¼ø¼¸¦ Á¶±Ý¾¿
¹Ù²ã°¡¸ç www0-www6
À» ¹ÝȯÇÑ´Ù. ±×·¡¼
Ŭ¶óÀ̾ðÆ®µéÀ» ¿©·¯ ¼¹ö·Î ºÐ»êÇÑ´Ù. ±×·¯³ª DNS
°Ë»ö °á°ú°¡ ³×Æ®¿÷ÀÇ ´Ù¸¥ ³×ÀÓ¼¹ö¿¡ ij½¬µÇ¿©
www.foo.com
À» ãÀº °á°ú°¡ ƯÁ¤
wwwN.foo.com
À̸é Ŭ¶óÀ̾ðÆ®ÀÇ ´ÙÀ½
¿äûµéµµ °°Àº wwwN.foo.com
À¸·Î
º¸³»Áö±â¶§¹®¿¡ ¿Ïº®ÇÑ ·Îµå¹ë·±½Ì ±â¹ýÀÌ ¾Æ´ÔÀ»
ÁÖÀÇÇ϶ó. ±×·¯³ª Å©°Ô º¸¸é ¿äûÀÌ ¿©·¯ À¥¼¹ö¿¡
ºÐ»êµÇ¹Ç·Î È¿°ú°¡ ÁÁ´Ù.
http://www.stanford.edu/~schemers/docs/lbnamed/lbnamed.html¿¡
ÀÖ´Â lbnamed
ÇÁ·Î±×·¥À» »ç¿ëÇÏ¿©
Á¤±³ÇÑ DNS±â¹Ý ·Îµå¹ë·±½ÌÀ» ÇÒ ¼ö ÀÖ´Ù. DNS°¡
½ÇÁ¦ ·Îµå¹ë·±½ÌÀ» Çϵµ·Ï ¸¸µå´Â ¿©·¯ µµ±¸¿Í Perl
5 ÇÁ·Î±×·¥ÀÌ´Ù.
ÀÌ ¹æ¹ýÀº mod_rewrite
¿Í proxy
throughput ±â´ÉÀ» »ç¿ëÇÑ´Ù. ¸ÕÀú DNS¿¡ ´ÙÀ½ Ç׸ñÀ»
»ç¿ëÇÏ¿© www0.foo.com
ÀÌ ½ÇÁ¦
www.foo.com
À» Àü´ãÇÏ°Ô ÇÑ´Ù
www IN CNAME www0.foo.com.
±×¸®°í www0.foo.com
À» ÇÁ·Ï½ÃÀü¿ë
¼¹ö·Î º¯°æÇÑ´Ù. Áï, URLÀ» ¹ÞÀ¸¸é ¼¹ö´Â ³»ºÎ
ÇÁ·Ï½Ã¸¦ ÅëÇØ ´Ù¸¥ 5´ë ¼¹öÁß (www1-www5
)
ÇÑ´ë·Î º¸³»±â¸¸ ÇÑ´Ù. À̸¦ À§ÇØ ¸ÕÀú ¸ðµç URLÀ»
·Îµå¹ë·±½Ì ½ºÅ©¸³Æ® lb.pl
·Î º¸³»´Â
±ÔÄ¢À» ¸¸µç´Ù.
RewriteEngine on RewriteMap lb prg:/path/to/lb.pl RewriteRule ^/(.+)$ ${lb:$1} [P,L]
lb.pl
À» ÀÛ¼ºÇÑ´Ù:
#!/path/to/perl ## ## lb.pl -- ·Îµå¹ë·±½Ì ½ºÅ©¸³Æ® ## $| = 1; $name = "www"; # ±âº» È£½ºÆ®¸í $first = 1; # ù¹ø° ¼¹ö (ÀÚ½ÅÀÌ 0À̱⠶§¹®¿¡, 0À» »ç¿ëÇÏÁö ¾Ê´Â´Ù) $last = 5; # round-robin¿¡¼ ¸¶Áö¸· ¼¹ö $domain = "foo.dom"; # µµ¸ÞÀθí $cnt = 0; while (<STDIN>) { $cnt = (($cnt+1) % ($last+1-$first)); $server = sprintf("%s%d.%s", $name, $cnt+$first, $domain); print "http://$server/$_"; } ##EOF##
www0.foo.com
¿¡ ºÎ´ãÀÌ °¡Áö¾Ê´Â°¡?
¹°·Ð, ºÎ´ãÀÌ µÈ´Ù. ±×·¯³ª ´Ü¼øÇÑ proxy throughput
¿äû¸¸ Çϱ⶧¹®¿¡ ±¦Âú´Ù! ¸ðµç SSI, CGI, ePerl
µîÀº ÀüÀûÀ¸·Î ´Ù¸¥ ¼¹ö°¡ ó¸®ÇÑ´Ù. ÀÌ°ÍÀÌ ÇÙ½ÉÀÌ´Ù.Çϵå¿þ¾î¸¦ »ç¿ëÇÑ ÇØ°áÃ¥µµ ÀÖ´Ù. Cisco´Â TCP/IP ¼öÁØ¿¡¼ ·Îµå¹ë·±½ÌÀ» ÇÏ´Â LocalDirector¶ó´Â ±«¹°À» ÆÇ´Ù. ½ÇÁ¦·Î´Â À¥¼¹ö±º ¾Õ´Ü¿¡ À§Ä¡ÇÏ´Â ÀÏÁ¾ÀÇ È¸·Î¼öÁØ °ÔÀÌÆ®¿þÀÌ´Ù. ÀÚ±ÝÀÌ ÃæºÐÇÏ°í °í¼º´É ÇØ°áÃ¥ÀÌ ÇÊ¿äÇÏ´Ù¸é ÀÌ°ÍÀ» »ç¿ëÇ϶ó.
³×Æ®¿÷¿¡´Â ¸ÚÁø CGI ÇÁ·Î±×·¥µéÀÌ ¸¹´Ù. ±×·¯³ª »ç¿ëÇϱâ
¹ø°Å·¯¿ö¼ ¸¹Àº À¥°ü¸®ÀÚ°¡ »ç¿ëÇÏÁö ¾Ê´Â´Ù. ¾ÆÆÄÄ¡ÀÇ
MIME-type¿¡ µû¸¥ Action Çڵ鷯 ±â´Éµµ CGI ÇÁ·Î±×·¥ÀÌ
Ưº°ÇÑ URLÀ» (Á¤È®È÷ PATH_INFO
¿Í
QUERY_STRINGS
) ÇÁ·Î±×·¥ÀÇ ÀÔ·ÂÀ¸·Î »ç¿ëÇÏÁö
¾ÊÀ» ¶§¸¸ ÀûÀýÇÏ´Ù. ¸ÕÀú, È®ÀåÀÚ°¡ (secure CGI¸¦ ÁÙ¿©)
.scgi
ÀÎ ÆÄÀÏÀ» À¯¸íÇÑ cgiwrap
ÇÁ·Î±×·¥À¸·Î ó¸®ÇϱâÀ§ÇØ »õ·Î¿î typeÀ» ¼³Á¤ÇÑ´Ù.
¹®Á¦´Â (À§¿¡¼ º») ÀÏ°üµÈ URL ±¸Á¶¸¦ »ç¿ëÇÏ´Â °æ¿ì
»ç¿ëÀÚ È¨µð·ºÅ丮°¡ /u/user/foo/bar.scgi
°°Àº
URLÀÎ Á¡ÀÌ´Ù. cgiwrap
´Â
/~user/foo/bar.scgi/
Çü½ÄÀÇ URLÀ»
¿øÇϱ⶧¹®ÀÌ´Ù. ´ÙÀ½ ±ÔÄ¢ÀÌ ¹®Á¦¸¦ ÇØ°áÇÑ´Ù:
RewriteRule ^/[uge]/([^/]+)/\.www/(.+)\.scgi(.*) ... ... /internal/cgi/user/cgiwrap/~$1/$2.scgi$3 [NS,T=application/x-http-cgi]
ÀÌÁ¦ ´Ù¸¥ ¸ÚÁø ÇÁ·Î±×·¥, (URL ÇÏÀ§Æ®¸®¿¡ ´ëÇÑ
access.log
¸¦ Ãâ·ÂÇÏ´Â) wwwlog
¿Í
(URL ÇÏÀ§Æ®¸®¿¡ Glimpse¸¦ ½ÇÇàÇÏ´Â) wwwidx
°¡
ÀÖ´Ù°í °¡Á¤ÇÏÀÚ. ¿ì¸®´Â ÇÁ·Î±×·¥¿¡°Ô ÀÛ¾÷ÇÒ ´ë»óÀÎ
URL ¿µ¿ªÀ» ¾Ë·ÁÁà¾ß ÇÑ´Ù. ±×·¯³ª ¿äûÇÒ¶§¸¶´Ù Ç×»ó
Àû¾îÁà¾ß Çϱ⶧¹®¿¡ ±ò²ûÇÏÁö ¾Ê´Ù. Áï, º¸Åë
/u/user/foo/
¿¡ ´ëÇØ swwidx
ÇÁ·Î±×·¥À» ½ÇÇàÇÑ´Ù¸é ´ÙÀ½°ú °°Àº ¸µÅ©¸¦ »ç¿ëÇÑ´Ù
/internal/cgi/user/swwidx?i=/u/user/foo/
±ò²ûÇÏÁö ¾Ê´Ù. ¸µÅ©¿¡ ¿µ¿ªÀÇ À§Ä¡¿Í CGI À§Ä¡¸¦ ¸ðµÎ Àû¾î¾ß Çϱ⶧¹®ÀÌ´Ù. ¿µ¿ªÀ» À籸¼ºÇÑ´Ù¸é ¿©·¯ ÇÏÀÌÆÛ¸µÅ©¸¦ ¼öÁ¤Çϴµ¥ ¸¹Àº ½Ã°£ÀÌ °É¸± °ÍÀÌ´Ù.
ÇØ°áÃ¥Àº ÀÚµ¿À¸·Î ÀûÀýÇÑ CGI¸¦ ½ÇÇàÇÏ´Â »õ·Î¿î Ưº°ÇÑ URL Çü½ÄÀ» ¸¸µå´Â °ÍÀÌ´Ù. ´ÙÀ½°ú °°ÀÌ ¼³Á¤ÇÑ´Ù:
RewriteRule ^/([uge])/([^/]+)(/?.*)/\* /internal/cgi/user/wwwidx?i=/$1/$2$3/ RewriteRule ^/([uge])/([^/]+)(/?.*):log /internal/cgi/user/wwwlog?f=/$1/$2$3
ÀÌÁ¦ /u/user/foo/
À» °Ë»öÇÏ´Â ¸µÅ©´Â
´ÙÀ½°ú °°´Ù
HREF="*" /u/user/foo/* (???)
³»ºÎÀûÀ¸·Î ´ÙÀ½°ú °°ÀÌ ÀÚµ¿º¯È¯µÈ´Ù
/internal/cgi/user/wwwidx?i=/u/user/foo/
°°Àº ¹æ¹ýÀ¸·Î ¸µÅ© µÚ¿¡ :log
¸¦ »ç¿ëÇÏ¿©
Á¢±Ù ·Î±× CGI ÇÁ·Î±×·¥À» ½ÇÇàÇÒ ¼ö ÀÖ´Ù.
¾î¶»°Ô ºê¶ó¿ìÀú¿Í »ç¿ëÀÚ°¡ ¸ð¸£°Ô ÀÚ¿¬½º·´°Ô Á¤Àû
ÆäÀÌÁö foo.html
À» µ¿ÀûÀÎ foo.cgi
·Î
º¯°æÇÒ ¼ö ÀÖ³ª.
URLÀ» CGI ½ºÅ©¸³Æ®·Î ÀçÀÛ¼ºÇÏ°í, MIME-typeÀ» ¼öÁ¤ÇÏ¿©
CGI ½ºÅ©¸³Æ®·Î ½ÇÇàÇÏ°Ô ÇÑ´Ù. ±×·¡¼
/~quux/foo.html
¸¦ ¿äûÇÏ¸é ³»ºÎÀûÀ¸·Î
/~quux/foo.cgi
¸¦ ½ÇÇàÇÏ°Ô µÈ´Ù.
RewriteEngine on RewriteBase /~quux/ RewriteRule ^foo\.html$ foo.cgi [T=application/x-httpd-cgi]
ÀÌ ¹æ¹ýÀº ½Ç·Î ºñ±âÀÌ´Ù: µ¿ÀûÀ¸·Î ÆäÀÌÁö¸¦ »ý¼ºÇÏÁö¸¸, Á¤ÀûÀ¸·Î ÆäÀÌÁö¸¦ ¼ºñ½ºÇÑ´Ù. Áï, ÆäÀÌÁö´Â ¼ø¼öÇÏ°Ô (ÆÄÀϽýºÅÛ¿¡¼ ÀÐÀº ³»¿ëÀ» ±×´ë·Î) Á¤Àû ÆäÀÌÁö·Î Àü´ÞµÇÁö¸¸, ¾øÀ» °æ¿ì À¥¼¹ö°¡ µ¿ÀûÀ¸·Î »ý¼ºÇÑ´Ù. ±×·¯¸é ´©°¡ (ȤÀº cron ÀÛ¾÷ÀÌ) Á¤Àû ÄÁÅÙÃ÷¸¦ Áö¿ìÁö¾Ê´Â ÇÑ CGI°¡ »ý¼ºÇÑ ÆäÀÌÁö¸¦ Á¤ÀûÀ¸·Î ¼ºñ½ºÇÑ´Ù. ÄÁÅÙÃ÷¸¦ Áö¿ì¸é ³»¿ëÀ» °»½ÅÇÑ´Ù.
RewriteCond %{REQUEST_FILENAME} !-s RewriteRule ^page\.html$ page.cgi [T=application/x-httpd-cgi,L]
¿©±â¼ page.html
¸¦ ¿äûÇÒ¶§
page.html
ÀÌ ¾ø°Å³ª ÆÄÀÏÅ©±â°¡ 0ÀÎ °æ¿ì
³»ºÎÀûÀ¸·Î page.cgi
¸¦ ½ÇÇàÇÑ´Ù. ¿©±â¼
ºñ°áÀº page.cgi
°¡ ÀϹÝÀûÀÎ CGI ½ºÅ©¸³Æ®¿Í
°°ÀÌ STDOUT
¿¡ Ãâ·ÂÇÏ°í, Ãß°¡·Î Ãâ·ÂÀ»
page.html
ÆÄÀÏ¿¡ Àû´Â´Ù. Çѹø ½ÇÇàÇÑÈÄ
¼¹ö´Â page.html
ÀÇ Á¤º¸¸¦ º¸³½´Ù. À¥°ü¸®ÀÚ°¡
°Àç·Î ³»¿ëÀ» °»½ÅÇÏ°í ½Í´Ù¸é, (º¸Åë cron ÀÛ¾÷ÀÌ)
page.html
À» Áö¿ì±â¸¸ ÇÏ¸é µÈ´Ù.
º¹ÀâÇÑ À¥ÆäÀÌÁö¸¦ ¸¸µé¶§ ÆíÁýÀÚ°¡ ³»¿ëÀ» ¼öÁ¤ÇÒ ¶§¸¶´Ù ÀÚµ¿À¸·Î ÆäÀÌÁö¸¦ »õ·Î °íħÇÏ´Â À¥ºê¶ó¿ìÀú°¡ ÀÖÀ¸¸é ¾ó¸¶³ª ÁÁÀ»±î? ºÒ°¡´ÉÇÑ°¡?
°¡´ÉÇÏ´Ù! MIME multipart ±â´É°ú À¥¼¹ö NPH ±â´É,
mod_rewrite
ÀÇ URL Á¶ÀÛ ´É·ÂÀ» °áÇÕÇϸé
µÈ´Ù. ¸ÕÀú, »õ·Î¿î URL ±â´ÉÀ» ¸¸µç´Ù: URL¿¡
:refresh
¸¦ Ãß°¡Çϱ⸸ Çϸé ÆÄÀϽýºÅÛ¿¡¼
¼öÁ¤µÉ ¶§¸¶´Ù »õ·Î °íħÇÑ´Ù.
RewriteRule ^(/[uge]/[^/]+/?.*):refresh /internal/cgi/apache/nph-refresh?f=$1
ÀÌÁ¦ ´ÙÀ½ URL¿¡ Á¢±ÙÇϸé
/u/foo/bar/page.html:refresh
´ÙÀ½ URLÀ» ³»ºÎÀûÀ¸·Î ºÎ¸¥´Ù
/internal/cgi/apache/nph-refresh?f=/u/foo/bar/page.html
ÀÌÁ¦ NPH-CGI ½ºÅ©¸³Æ®¸¸ ³²¾Ò´Ù. º¸Åë "µ¶ÀÚ¿¡°Ô ¿¬½ÀÀ¸·Î ³²°ÜµÒ"À̶ó°í ¸»ÇÏÁö¸¸ ;-) ³ª´Â À̰͵µ Á¦°øÇÑ´Ù.
#!/sw/bin/perl ## ## nph-refresh -- NPH/CGI script for auto refreshing pages ## Copyright (c) 1997 Ralf S. Engelschall, All Rights Reserved. ## $| = 1; # split the QUERY_STRING variable @pairs = split(/&/, $ENV{'QUERY_STRING'}); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $name =~ tr/A-Z/a-z/; $name = 'QS_' . $name; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; eval "\$$name = \"$value\""; } $QS_s = 1 if ($QS_s eq ''); $QS_n = 3600 if ($QS_n eq ''); if ($QS_f eq '') { print "HTTP/1.0 200 OK\n"; print "Content-type: text/html\n\n"; print "<b>ERROR</b>: No file given\n"; exit(0); } if (! -f $QS_f) { print "HTTP/1.0 200 OK\n"; print "Content-type: text/html\n\n"; print "<b>ERROR</b>: File $QS_f not found\n"; exit(0); } sub print_http_headers_multipart_begin { print "HTTP/1.0 200 OK\n"; $bound = "ThisRandomString12345"; print "Content-type: multipart/x-mixed-replace;boundary=$bound\n"; &print_http_headers_multipart_next; } sub print_http_headers_multipart_next { print "\n--$bound\n"; } sub print_http_headers_multipart_end { print "\n--$bound--\n"; } sub displayhtml { local($buffer) = @_; $len = length($buffer); print "Content-type: text/html\n"; print "Content-length: $len\n\n"; print $buffer; } sub readfile { local($file) = @_; local(*FP, $size, $buffer, $bytes); ($x, $x, $x, $x, $x, $x, $x, $size) = stat($file); $size = sprintf("%d", $size); open(FP, "<$file"); $bytes = sysread(FP, $buffer, $size); close(FP); return $buffer; } $buffer = &readfile($QS_f); &print_http_headers_multipart_begin; &displayhtml($buffer); sub mystat { local($file) = $_[0]; local($time); ($x, $x, $x, $x, $x, $x, $x, $x, $x, $mtime) = stat($file); return $mtime; } $mtimeL = &mystat($QS_f); $mtime = $mtime; for ($n = 0; $n < $QS_n; $n++) { while (1) { $mtime = &mystat($QS_f); if ($mtime ne $mtimeL) { $mtimeL = $mtime; sleep(2); $buffer = &readfile($QS_f); &print_http_headers_multipart_next; &displayhtml($buffer); sleep(5); $mtimeL = &mystat($QS_f); last; } sleep($QS_s); } } &print_http_headers_multipart_end; exit(0); ##EOF##
°¡»óÈ£½ºÆ®°¡ ¸î°³¸¸ ÀÖ´Ù¸é ¾ÆÆÄÄ¡ÀÇ <VirtualHost>
±â´ÉÀÌ Àß µ¿ÀÛÇÑ´Ù. ±×·¯³ª °¡»óÈ£½ºÆ®°¡ ¼ö¹é°³ ÀÖ´Â
ISP¶ó¸é ÀÌ ±â´ÉÀÌ ÃÖ¼±Àº ¾Æ´Ï´Ù.
ÀÌ ±â´ÉÀ» Á¦°øÇÏ·Á¸é Proxy Throughput
±â´ÉÀ» (Ç÷¡±× [P]
) »ç¿ëÇÏ¿© ¿ÜºÎ À¥ÆäÀÌÁö
ȤÀº Àüü ¿ÜºÎ À¥¿µ¿ªÀ» ¿ì¸®ÀÇ À̸§°ø°£¿¡ ´ëÀÀÇÑ´Ù:
## ## vhost.map ## www.vhost1.dom:80 /path/to/docroot/vhost1 www.vhost2.dom:80 /path/to/docroot/vhost2 : www.vhostN.dom:80 /path/to/docroot/vhostN
## ## httpd.conf ## : # ¸®´ÙÀÌ·ºÆ®ÇÒ¶§ Á¤±Ô È£½ºÆ®¸íÀ» »ç¿ëÇÑ´Ù. UseCanonicalName on : # °¡»óÈ£½ºÆ®¸¦ CLF Çü½Ä ¾Õ¿¡ Ãß°¡ÇÑ´Ù CustomLog /path/to/access_log "%{VHOST}e %h %l %u %t \"%r\" %>s %b" : # ÁÖ¼¹ö¿¡¼ ÀçÀÛ¼º ¿£ÁøÀ» »ç¿ëÇÑ´Ù RewriteEngine on # µÎ ¸ÊÀ» Á¤ÀÇÇÑ´Ù: Çϳª´Â URLÀ» °íÄ¡°í, # ´Ù¸¥ Çϳª´Â °¡»óÈ£½ºÆ®º° DocumentRoot¸¦ # Á¤ÀÇÇÑ´Ù. RewriteMap lowercase int:tolower RewriteMap vhost txt:/path/to/vhost.map # ÀÌÁ¦ Å©°í º¹ÀâÇÑ ±ÔÄ¢ ÇÑ°³¸¦ »ç¿ëÇÏ¿© # °¡»óÈ£½ºÆ®·Î ´ëÀÀÇÑ´Ù. # # 1. °¡»óÈ£½ºÆ®µéÀÌ °°ÀÌ »ç¿ëÇÏ´Â À§Ä¡´Â ´ëÀÀÇÏÁö ¾Ê´Â´Ù RewriteCond %{REQUEST_URL} !^/commonurl1/.* RewriteCond %{REQUEST_URL} !^/commonurl2/.* : RewriteCond %{REQUEST_URL} !^/commonurlN/.* # # 2. ¿ì¸®°¡ ÇöÀç »ç¿ëÇÏ´Â ¹æ¹ýÀÌ Host Çì´õ¸¦ # °¡»óÈ£½ºÆ®¸¦ Áö¿øÇϹǷΠ# Host Çì´õ°¡ ÀÖ´ÂÁö È®ÀÎÇÑ´Ù RewriteCond %{HTTP_HOST} !^$ # # 3. È£½ºÆ®¸íÀ» ¼Ò¹®ÀÚ·Î ¸¸µç´Ù RewriteCond ${lowercase:%{HTTP_HOST}|NONE} ^(.+)$ # # 4. vhost.map¿¡¼ È£½ºÆ®¸íÀ» ã°í # °æ·ÎÀ϶§¸¸ ±â¾ïÇÑ´Ù # (À§¿¡¼ "NONE"Àº ¾Æ´Ï´Ù) RewriteCond ${vhost:%1} ^(/.*)$ # # 5. ¸¶Áö¸·À¸·Î URLÀ» ¹®¼ À§Ä¡·Î ´ëÀÀÇÏ°í # ·Î±×¿¡ ³²±â±âÀ§ÇØ °¡»óÈ£½ºÆ®¸¦ ±â¾ïÇØ µÐ´Ù RewriteRule ^/(.*)$ %1/$1 [E=VHOST:${lowercase:%{HTTP_HOST}}] :
¾î¶»°Ô Çϸé ƯÁ¤ À¥°ø°£ÀÇ ÆäÀÌÁö¸¦ ±Ü¾î¸ðÀ¸´Â ±ÍÂúÀº
·Îº¿À» ¸·À» ¼ö ÀÖ³ª? "Robot Exclusion Protocol" Ç׸ñÀ»
ÀúÀåÇÑ /robots.txt
ÆÄÀÏÀº º¸Åë ÀÌ·± ·Îº¿À»
¸·´Âµ¥ ÃæºÐÇÏÁö ¾Ê´Ù.
(¾Æ¸¶µµ µð·ºÅ丮°¡ ±í¾î¼ ·Îº¿ÀÌ µ¹¾Æ´Ù´Ï¸é ¼¹ö¿¡
ºÎ´ãÀÌ Å« °æ¿ì) À¥°ø°£ /~quux/foo/arc/
¿¡
ÀÖ´Â URLµéÀ» °ÅºÎÇÏ´Â ±ÔÄ¢À» »ç¿ëÇÑ´Ù. ¿ì¸®´Â ƯÁ¤
·Îº¿ÀÇ Á¢±ÙÀ» ¸·¾Æ¾ß ÇÑ´Ù. Áï, ·Îº¿À» ½ÇÇàÇϴ ȣ½ºÆ®¸¦
¸·´Â °ÍÀ¸·Î´Â ºÒÃæºÐÇϸç, ±× È£½ºÆ®ÀÇ »ç¿ëÀÚµµ ¸·¾Æ¹ö¸®°Ô
µÈ´Ù. User-Agent HTTP Çì´õ Á¤º¸µµ ºñ±³ÇÑ´Ù.
RewriteCond %{HTTP_USER_AGENT} ^NameOfBadRobot.* RewriteCond %{REMOTE_ADDR} ^123\.45\.67\.[8-9]$ RewriteRule ^/~quux/foo/arc/.+ - [F]
http://www.quux-corp.de/~quux/
¿¡ ÀÖ´Â
ÆäÀÌÁöµéÀÌ GIF ±×¸²À» Æ÷ÇÔÇÑ´Ù°í °¡Á¤ÇÏÀÚ. ÀÌ ±×¸²ÀÌ
¸ÚÀÖ¾î¼, ´Ù¸¥ »ç¶÷µéÀÌ ÀÚ½ÅÀÇ ÆäÀÌÁö¿¡ Á÷Á¢ ¸µÅ©¸¦
°Ç´Ù. ¼¹ö¿¡ ºÒÇÊ¿äÇÑ ºÎ´ãÀÌ µÇ¹Ç·Î ¸·°í ½Í´Ù.
±×¸²À» 100% º¸È£ÇÒ ¼ö´Â ¾øÁö¸¸, ÃÖ¼ÒÇÑ ºê¶ó¿ìÀú°¡ HTTP Referer Çì´õ¸¦ º¸³»´Â °æ¿ì Á¦ÇÑÇÒ ¼ö ÀÖ´Ù.
RewriteCond %{HTTP_REFERER} !^$ RewriteCond %{HTTP_REFERER} !^http://www.quux-corp.de/~quux/.*$ [NC] RewriteRule .*\.gif$ - [F]
RewriteCond %{HTTP_REFERER} !^$ RewriteCond %{HTTP_REFERER} !.*/foo-with-gif\.html$ RewriteRule ^inlined-in-foo\.gif$ - [F]
¾î¶»°Ô ¿ÜºÎ¿¡¼ ¼¹ö¿¡ Á¢±ÙÇÒ ¼ö ¾ø´Â È£½ºÆ® ¸ñ·ÏÀ» ¼³Á¤ÇÒ ¼ö ÀÖ³ª?
¾ÆÆÄÄ¡ >= 1.3b6¿¡¼:
RewriteEngine on RewriteMap hosts-deny txt:/path/to/hosts.deny RewriteCond ${hosts-deny:%{REMOTE_HOST}|NOT-FOUND} !=NOT-FOUND [OR] RewriteCond ${hosts-deny:%{REMOTE_ADDR}|NOT-FOUND} !=NOT-FOUND RewriteRule ^/.* - [F]
¾ÆÆÄÄ¡ <= 1.3b6¿¡¼:
RewriteEngine on RewriteMap hosts-deny txt:/path/to/hosts.deny RewriteRule ^/(.*)$ ${hosts-deny:%{REMOTE_HOST}|NOT-FOUND}/$1 RewriteRule !^NOT-FOUND/.* - [F] RewriteRule ^NOT-FOUND/(.*)$ ${hosts-deny:%{REMOTE_ADDR}|NOT-FOUND}/$1 RewriteRule !^NOT-FOUND/.* - [F] RewriteRule ^NOT-FOUND/(.*)$ /$1
## ## hosts.deny ## ## ÁÖÀÇ! ÀÌ°ÍÀº ¸ñ·Ïó·³ º¸ÀÌÁö¸¸ ¸ñ·ÏÀÌ ¾Æ´Ï¶ó ¸ÊÀÌ´Ù. ## mod_rewrite´Â ÀÌ Á¤º¸¸¦ Å°/°ª ½ÖÀ¸·Î Çؼ®Çϱ⶧¹®¿¡, ## °¢ Ç׸ñÀÇ °ª ÀÚ¸®¿¡ ÃÖ¼ÒÇÑ "-"°¡ ÇÊ¿äÇÏ´Ù. ## 193.102.180.41 - bsdti1.sdm.de - 192.76.162.40 -
¾î¶»°Ô ƯÁ¤ È£½ºÆ® ȤÀº ƯÁ¤ È£½ºÆ®ÀÇ »ç¿ëÀÚ°¡ ¾ÆÆÄÄ¡ ÇÁ·Ï½Ã¸¦ »ç¿ëÇÒ ¼ö ¾øµµ·Ï Çϳª?
¸ÕÀú ¾ÆÆÄÄ¡ À¥¼¹ö¸¦ ÄÄÆÄÀÏÇÒ¶§ ±¸¼ºÆÄÀÏ¿¡¼
mod_rewrite
°¡ mod_proxy
¾Æ·¡¿¡(!) ÀÖ¾î¾ß ÇÑ´Ù. ±×·¯¸é mod_rewrite
´Â
mod_proxy
ÀÌÀü¿¡ ºÒ¸°´Ù.
ÀÌÁ¦ ´ÙÀ½°ú °°ÀÌ Æ¯Á¤ È£½ºÆ®¸¦ °ÅºÎÇϵµ·Ï ¼³Á¤ÇÑ´Ù...
RewriteCond %{REMOTE_HOST} ^badhost\.mydomain\.com$ RewriteRule !^http://[^/.]\.mydomain.com.* - [F]
...±×¸®°í ´ÙÀ½Àº user@host¿¡ µû¶ó °ÅºÎÇÑ´Ù:
RewriteCond %{REMOTE_IDENT}@%{REMOTE_HOST} ^badguy@badhost\.mydomain\.com$ RewriteRule !^http://[^/.]\.mydomain.com.* - [F]
°¡²û ¸Å¿ì Ưº°ÇÑ ÀÎÁõÀÌ ÇÊ¿äÇÒ ¶§°¡ ÀÖ´Ù. ¿¹¸¦
µé¾î, ¹Ì¸® ¼³Á¤ÇصР»ç¿ëÀÚÀÎÁö °Ë»çÇÑ´Ù. À̵鿡°Ô¸¸
(mod_auth_basic
ÀÇ Basic Auth¸¦ »ç¿ëÇÑ
°æ¿ì¿Í ´Þ¸®) º°´Ù¸¥ ¹°À½¾øÀÌ Á¢±ÙÀ» Çã¿ëÇÑ´Ù.
Ä£±¸¸¸ Á¢±ÙÀÌ °¡´ÉÇϵµ·Ï ÀçÀÛ¼º ±ÔÄ¢µéÀ» »ç¿ëÇÑ´Ù:
RewriteCond %{REMOTE_IDENT}@%{REMOTE_HOST} !^friend1@client1.quux-corp\.com$ RewriteCond %{REMOTE_IDENT}@%{REMOTE_HOST} !^friend2@client2.quux-corp\.com$ RewriteCond %{REMOTE_IDENT}@%{REMOTE_HOST} !^friend3@client3.quux-corp\.com$ RewriteRule ^/~quux/only-for-friends/ - [F]
"Referer" HTTP Çì´õ¿¡ µû¶ó ¿øÇϴ´ë·Î ÂüÁ¶ÆäÀÌÁö¸¦ ¼³Á¤ÇÒ ¼ö ÀÖ´Â À¯¿¬ÇÑ URL º¯È¯±â¸¦ ¸¸µé ¼ö Àִ°¡?
´ÙÀ½°ú °°ÀÌ º¹ÀâÇÑ ±ÔÄ¢À»...
RewriteMap deflector txt:/path/to/deflector.map RewriteCond %{HTTP_REFERER} !="" RewriteCond ${deflector:%{HTTP_REFERER}} ^-$ RewriteRule ^.* %{HTTP_REFERER} [R,L] RewriteCond %{HTTP_REFERER} !="" RewriteCond ${deflector:%{HTTP_REFERER}|NOT-FOUND} !=NOT-FOUND RewriteRule ^.* ${deflector:%{HTTP_REFERER}} [R,L]
... ÀçÀÛ¼º ¸Ê°ú °°ÀÌ »ç¿ëÇÑ´Ù:
## ## deflector.map ## http://www.badguys.com/bad/index.html - http://www.badguys.com/bad/index2.html - http://www.badguys.com/bad/index3.html http://somewhere.com/
±×·¯¸é ¿äûÀ» ÀÚµ¿À¸·Î (¸Ê¿¡¼ °ªÀ¸·Î "-
"¸¦
»ç¿ëÇÑ °æ¿ì) ÂüÁ¶ÆäÀÌÁö³ª (URLÀÌ ¸Ê¿¡ ÀÖ´Â °æ¿ì µÎ¹ø°
¾Æ±Ô¸ÕÆ®·Î) ƯÁ¤ URL·Î ¸®´ÙÀÌ·º¼ÇÇÑ´Ù.
FAQ: ¾î¶»°Ô ÀÌ·±Àú·± Àâ´ÙÇÑ ¹®Á¦¸¦ Ç® ¼ö Àִ°¡?
mod_rewrite
·Î´Â ÇØ°áÃ¥ÀÌ ¾Èº¸ÀδÙ...
¿ÜºÎ RewriteMap
À» »ç¿ëÇ϶ó.
Áï, ÇÁ·Î±×·¥ÀÌ RewriteMap
¿ªÇÒÀ»
ÇÑ´Ù. ÇÁ·Î±×·¥Àº ¾ÆÆÄÄ¡°¡ ½ÃÀÛÇÒ¶§ ½ÃÀÛÇÏ¿©
STDIN
¿¡¼ ¿äûÇÑ URLÀ» ¹Þ°í, (°°Àº ¼ø¼·Î!)
°á°ú (º¸Åë ÀçÀÛ¼ºµÈ) URLÀ» STDOUT
¿¡ Ãâ·ÂÇÑ´Ù.
RewriteEngine on RewriteMap quux-map prg:/path/to/map.quux.pl RewriteRule ^/~quux/(.*)$ /~quux/${quux-map:$1}
#!/path/to/perl # ¾ÆÆÄÄ¡ ¼¹ö°¡ ¸ØÃßÁö ¾Êµµ·Ï # ÀÔÃâ·Â ¹öÆÛ¸¦ »ç¿ëÇÏÁö ¾Ê´Â´Ù $| = 1; # stdin¿¡¼ ÇÑÁÙ¾¿ URLÀ» Àаí # stdout¿¡ º¯È¯ÇÑ URLÀ» Ãâ·ÂÇÑ´Ù while (<>) { s|^foo/|bar/|; print $_; }
¼³¸íÇϱâÀ§ÇØ ¸ðµç /~quux/foo/...
URLÀ»
/~quux/bar/...
·Î ÀçÀÛ¼ºÇÏ´Â ½ºÅ©¸³Æ®¸¦
¿¹·Î µé¾ú´Ù. ½ÇÁ¦·Î ¸¶À½´ë·Î ÇÁ·Î±×·¡¹ÖÇÒ ¼ö ÀÖ´Ù.
±×·¯³ª ÀÏ¹Ý »ç¿ëÀÚ°¡ ÀÌ·± ¸ÊÀ» »ç¿ëÇÒ
¼ö ÀÖ´Ù°í ÇÏ´õ¶ó°í, ¿ÀÁ÷ ½Ã½ºÅÛ °ü¸®ÀÚ¸¸ÀÌ ¸ÊÀ»
Á¤ÀÇÇØ¾ß ÇÔÀ» ÁÖÀÇÇ϶ó.