ÔõÑùʹÓø¡Í¼Ãæ°å¾ÙÐз´ÏòÊðÀí»º´æÉèÖÃ
Ëæ×Å»¥ÁªÍøµÄÒ»Ö±Éú³¤£¬ÍøÕ¾µÄ»á¼ûÁ¿Ô½À´Ô½´ó£¬¹ØÓÚÍøÕ¾µÄÐÔÄÜÒ²Ìá³öÁ˸ü¸ßµÄÒªÇó¡£·´ÏòÊðÀí»º´æ¿ÉÒÔÌá¸ßÍøÕ¾µÄ»á¼ûËÙÂÊ£¬¼õÇáЧÀÍÆ÷µÄ¸ºÔØ£¬ÎªÓû§Ìṩ¸üºÃµÄ»á¼ûÌåÑé¡£±¾ÎĽ«ÏÈÈÝÔõÑùʹÓø¡Í¼Ãæ°å¾ÙÐз´ÏòÊðÀí»º´æÉèÖá£
Ò»¡¢Ê²Ã´ÊÇ·´ÏòÊðÀí»º´æ
·´ÏòÊðÀí»º´æÊÇÖ¸ÔÚЧÀÍÆ÷Óë¿Í»§¶ËÖ®¼äÔöÌíÒ»¸ö·´ÏòÊðÀíЧÀÍÆ÷£¬µ±¿Í»§¶ËÏòЧÀÍÆ÷ÌᳫÇëÇóʱ£¬ÇëÇó²»Ö±½Ó·¢Ë͸øЧÀÍÆ÷£¬¶øÊÇÏÈ·¢Ë͸ø·´ÏòÊðÀíЧÀÍÆ÷£¬·´ÏòÊðÀíЧÀÍÆ÷ÔÙÏòЧÀÍÆ÷ÌᳫÇëÇ󣬲¢½«Ð§ÀÍÆ÷·µ»ØµÄÊý¾Ý»º´æÏÂÀ´¡£µ±Ï´ÎÓÐÏàͬµÄÇëÇóʱ£¬·´ÏòÊðÀíЧÀÍÆ÷»áÖ±½Ó·µ»Ø»º´æµÄÊý¾Ý£¬×èÖ¹ÁËÔÙ´ÎÏòЧÀÍÆ÷ÇëÇóÊý¾Ý£¬Ìá¸ßÁËÍøÕ¾µÄ»á¼ûËÙÂÊ£¬¼õÇáÁËЧÀÍÆ÷µÄ¸ºÔØ¡£
¶þ¡¢ÔõÑùʹÓø¡Í¼Ãæ°å¾ÙÐз´ÏòÊðÀí»º´æÉèÖÃ
µÇ¼¸¡Í¼Ãæ°å²¢½¨ÉèÕ¾µã
Ê×ÏȵǼ¸¡Í¼Ãæ°å£¬ÔÚ×ó²à²Ëµ¥ÖÐÑ¡Ôñ¡°ÍøÕ¾¡±£¬È»ºóµ¥»÷¡°Ìí¼ÓÕ¾µã¡±£¬ÊäÈëÓòÃûºÍÕ¾µãĿ¼£¬Ñ¡ÔñÍøÕ¾ÀàÐÍΪ¡°·´ÏòÊðÀí¡±£¬µ¥»÷¡°½¨ÉèÕ¾µã¡±°´Å¥¡£
ÉèÖ÷´ÏòÊðÀí¹æÔò
½øÈëÕ¾µãÖÎÀíÒ³Ã棬µ¥»÷×ó²à²Ëµ¥µÄ¡°·´ÏòÊðÀí¡±Ñ¡Ï£¬ÔÚ¡°·´ÏòÊðÀí¹æÔò¡±ÖÐÌí¼ÓÐèÒª»º´æµÄÓòÃû¼°Æä¶ÔÓ¦µÄ·´ÏòÊðÀíµØµã¡£ÀýÈ磬¼ÙÉèÎÒÃÇҪΪwww.example.comÌí¼Ó·´ÏòÊðÀí»º´æ£¬Æä·´ÏòÊðÀíµØµãΪ192.168.1.10£¬¶Ë¿ÚΪ80£¬Ôò·´ÏòÊðÀí¹æÔòӦΪ£º
location / {
proxy_pass http://192.168.1.10:80;
proxy_cache_bypass $http_pragma;
proxy_cache_revalidate on;
proxy_cache_valid any 1d;
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=cache_zone:10m inactive=60m;
proxy_cache_key “$scheme$request_method$host$request_uri”;
add_header X-Cache-Status $upstream_cache_status;
}
ÉÏÊö¹æÔòÖУ¬proxy_passÖ¸¶¨·´ÏòÊðÀíµØµã£¬proxy_cache_pathÖ¸¶¨»º´æ·¾¶ºÍÃû³Æ£¬proxy_cache_keyÖ¸¶¨»º´ækey£¬proxy_cache_validÖ¸¶¨»º´æʱ¼ä¡£
ÉúÑÄÉèÖò¢²âÊÔ
Ìí¼ÓÍê·´ÏòÊðÀí¹æÔòºó£¬µ¥»÷¡°ÉúÑÄ¡±°´Å¥ÉúÑÄÉèÖ㬲¢ÔÚÍøÕ¾ÖÎÀíÒ³Ãæµ¥»÷¡°ÖØÆô¡±°´Å¥ÖØÆôNginxЧÀÍÆ÷¡£Íê³ÉÒÔÉϲÙ×÷ºó£¬¾Í¿ÉÒÔ²âÊÔ·´ÏòÊðÀí»º´æÊÇ·ñÉúЧÁË¡£¿ÉÒÔʹÓÃä¯ÀÀÆ÷»á¼ûwww.example.com£¬»á¼ûÍøÕ¾ºó£¬Ôٴλá¼ûͳһÍøÖ·£¬¿´¿´ÊÇ·ñÄܹ»´Ó»º´æÖлñÈ¡Êý¾Ý£¬ÈôÊÇ¿ÉÒÔ£¬ËµÃ÷·´ÏòÊðÀí»º´æÒѾÉúЧ¡£
Èý¡¢×ܽá
·´ÏòÊðÀí»º´æ¿ÉÒÔÌá¸ßÍøÕ¾µÄ»á¼ûËÙÂÊ£¬¼õÇáЧÀÍÆ÷µÄ¸ºÔØ¡£¸¡Í¼Ãæ°åÌṩÁ˼òÆÓÒ×Óõķ´ÏòÊðÀí»º´æÉèÖù¦Ð§£¬Ö»ÐèÒª¼¸¸ö°ì·¨¾Í¿ÉÒÔÍê³É·´ÏòÊðÀí»º´æµÄÉèÖá£Ï£ÍûÕâƪÎÄÕÂÄܹ»×ÊÖúÄúÉèÖ÷´ÏòÊðÀí»º´æ£¬Ìá¸ßÍøÕ¾µÄÐÔÄܺÍÓû§ÌåÑé¡£
ÒÔÉϾÍÊÇÔõÑùʹÓø¡Í¼Ãæ°å¾ÙÐз´ÏòÊðÀí»º´æÉèÖõÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡