nginx¸ºÔØƽºâÔõÑùʵÏÖ
nginx ¸ºÔØƽºâͨ¹ý upstream Ä£¿é½ç˵ºó¶ËЧÀÍÆ÷£¬²¢Ê¹Óà location ¿é½«ÇëÇóÊðÀíµ½ÕâЩЧÀÍÆ÷¡£Ö§³ÖÂÖѯ¡¢×îÉÙÅþÁ¬Êý¡¢ÏìӦʱ¼ä¼ÓȨºÍ ip_hash µÈ¸ºÔØƽºâÕ½ÂÔ¡£ÉèÖÃʾÀý°üÀ¨½ç˵ upstream ×éºÍʹÓà proxy_pass Ö¸ÁîÖ¸ÏòËü¡£
Nginx ¸ºÔØƽºâʵÏÖ
Nginx ¸ºÔØƽºâ½ç˵
Nginx ¸ºÔØƽºâÊÇָͨ¹ý Nginx ·Ö·¢ÇëÇóÁ÷Á¿µ½¶à¸öºó¶ËЧÀÍÆ÷£¬ÒÔÌá¸ßÍøÕ¾»òÓ¦ÓóÌÐòµÄÐÔÄÜ¡¢ÎȹÌÐԺͿÉÀ©Õ¹ÐÔ¡£
ʵÏÖ·½·¨
Nginx ¸ºÔØƽºâÖ÷Ҫͨ¹ýÒÔÏ·½·¨ÊµÏÖ£º
upstream Ä£¿é£º½ç˵ºó¶ËЧÀÍÆ÷×飬²¢ÉèÖÃÆ俵½¡¼ì²éºÍ¸ºÔØƽºâÕ½ÂÔ¡£
location ¿é£ºÊ¹Óà proxy_pass Ö¸ÁÇëÇóÊðÀíµ½ upstream Ä£¿é½ç˵µÄºó¶ËЧÀÍÆ÷¡£
¸ºÔØƽºâÕ½ÂÔ
Nginx Ö§³Ö¶àÖÖ¸ºÔØƽºâÕ½ÂÔ£¬°üÀ¨£º
ÂÖѯ£º°´Ë³Ðò½«ÇëÇó·ÖÅɵ½ºó¶ËЧÀÍÆ÷¡£
×îÉÙÅþÁ¬Êý£º½«ÇëÇó·ÖÅɵ½ÅþÁ¬Êý×îÉÙµÄЧÀÍÆ÷¡£
ÏìӦʱ¼ä¼ÓȨ£ºÆ¾Ö¤ºó¶ËЧÀÍÆ÷µÄÏìӦʱ¼ä£¬½«ÇëÇó·ÖÅɵ½ÏìӦʱ¼ä×î¶ÌµÄЧÀÍÆ÷¡£
ip_hash£ºÆ¾Ö¤¿Í»§¶Ë IP µØµã£¬½«ÇëÇóÉ¢Áе½Ìض¨ºó¶ËЧÀÍÆ÷¡£
ÉèÖÃʾÀý
ÒÔÏÂÊÇÒ»¸ö¼òÆ Nginx ¸ºÔØƽºâÉèÖÃʾÀý£º
upstream backend { server 192.168.1.10:80 weight=1; server 192.168.1.11:80 weight=1; server 192.168.1.12:80 backup; } server { listen 80; location / { proxy_pass http://backend; } }
µÇ¼ºó¸´ÖÆ
´ËÉèÖý« 192.168.1.10 ºÍ 192.168.1.11 ЧÀÍÆ÷×÷ΪÖ÷ºó¶ËЧÀÍÆ÷£¬Ê¹ÓÃÂÖѯսÂÔ·ÖÅÉÇëÇó¡£192.168.1.12 ЧÀÍÆ÷Ϊ±¸ÓÃЧÀÍÆ÷£¬½öÔÚÖ÷ЧÀÍÆ÷²»¿ÉÓÃʱÆôÓá£
ÒÔÉϾÍÊÇnginx¸ºÔØƽºâÔõÑùʵÏÖµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡