×ðÁú¿­Ê±

NginxÐéÄâÖ÷»ú¸ºÔØƽºâÉèÖà £¬ÊµÏÖ¶àÓòÃûÊ¿Á¿·Ö·¢

nginxÐéÄâÖ÷»ú¸ºÔØƽºâÉèÖà £¬ÊµÏÖ¶àÓòÃûÊ¿Á¿·Ö·¢

СÐò£º

ÔÚÏÖ´úÍøÂçÓ¦ÓóÌÐòÖÐ £¬¸ºÔØƽºâÊÇÌá¸ßϵͳÎȹÌÐÔºÍÐÔÄܵÄÖ÷ÒªÒòËØ¡£Nginx×÷Ϊһ¿î¸ßÐÔÄܵÄWebЧÀÍÆ÷ £¬¿ÉÒÔʹÓÃÆäÇ¿Ê¢µÄ¸ºÔØƽºâ¹¦Ð§À´ÊµÏÖ¶àÓòÃûÊ¿Á¿·Ö·¢¡£±¾ÎĽ«ÏÈÈÝÔõÑùÉèÖÃNginxÐéÄâÖ÷»ú¸ºÔØƽºâ £¬´Ó¶øʵÏÖ¶à¸öÓòÃûµÄÁ÷Á¿·Ö·¢¡£

Ò»¡¢»ù´¡ÇéÐÎ×¼±¸£º

ÔÚ×îÏÈ֮ǰ £¬ÎÒÃÇÐèҪȷ±£ÒѾ­×°ÖÃÁËNginx £¬²¢ÇҾ߱¸ÒÔϼ¸¸ö»ù´¡ÒªËØ£º

¶à¸öÓòÃûÖ¸Ïòͳһ¸öЧÀÍÆ÷IP£»

ÿ¸öÓòÃûÒѾ­ÔÚNginxµÄÉèÖÃÎļþÖоÙÐÐÁËÉèÖá£

¶þ¡¢NginxÐéÄâÖ÷»ú¸ºÔØƽºâÉèÖð취£º

½¨ÉèÒ»¸öеÄÉèÖÃÎļþvhost.conf£º

ÔÚNginxµÄÉèÖÃĿ¼Ï £¬Ð½¨Ò»¸öÃûΪvhost.confµÄÎļþ £¬²¢ÔÚ¸ÃÎļþÖÐÌí¼ÓÈçÏÂÄÚÈÝ£º

http {
 upstream backend {
     server backend1.example.com;
     server backend2.example.com;
     server backend3.example.com;
 }

 server {
     listen 80;
     server_name example.com;

     location / {
         proxy_pass http://backend;
     }
 }
}

µÇ¼ºó¸´ÖÆ

ÔÚÕâ¸öÉèÖÃÎļþÖÐ £¬ÎÒÃǽç˵ÁËÒ»¸öÃûΪbackendµÄ¸ºÔØƽºâ¼¯Èº £¬ÆäÖÐbackend1.example.com¡¢backend2.example.com¡¢backend3.example.comÊǺó¶ËЧÀÍÆ÷µÄÓòÃû»òIPµØµã¡£ÔÚserver¿éÖÐ £¬ÎÒÃÇÖ¸¶¨¼àÌý80¶Ë¿Ú £¬²¢½«ËùÓÐÇëÇóת·¢µ½backend¼¯Èº¡£

ÐÞ¸ÄÖ÷ÉèÖÃÎļþnginx.conf£º

·­¿ªNginxµÄÖ÷ÉèÖÃÎļþnginx.conf £¬²¢ÔÚhttp¿éÖеÄincludeÓï¾äÖÐÌí¼ÓÈçÏÂÄÚÈÝ£º

http {
 ...
 include /path/to/vhost.conf;
 ...
}

µÇ¼ºó¸´ÖÆ

½«/path/to/vhost.confÌæ»»³ÉÏÖʵµÄvhost.confÎļþ·¾¶¡£

ÖØмÓÔØNginxÉèÖãº

ÉúÑÄvhost.confºÍnginx.confÎļþµÄÐÞ¸Ä £¬²¢ÔËÐÐÒÔÏÂÏÂÁîÖØмÓÔØNginxµÄÉèÖÃÎļþ£º

nginx -s reload

µÇ¼ºó¸´ÖÆ

Èý¡¢²âÊÔÓëÑéÖ¤£º

Íê³ÉÉÏÊöÉèÖúó £¬ÎÒÃÇ¿ÉÒÔͨ¹ýÒÔÏ°취¾ÙÐвâÊÔÓëÑéÖ¤£º

ÐÞ¸ÄÍâµØhostsÎļþ£º

½«example.comµÄÆÊÎöµØµãÐÞ¸ÄΪNginxЧÀÍÆ÷µÄIPµØµã¡£ÔÚWindowsϵͳÖÐ £¬hostsÎļþλÓÚC:WindowsSystem32driversetchosts £¬ÔÚLinuxϵͳÖÐ £¬hostsÎļþλÓÚ/etc/hosts¡£

ÔÚä¯ÀÀÆ÷Öлá¼û²âÊÔÓòÃû£º

ÔÚä¯ÀÀÆ÷ÖÐÊäÈëhttp://example.com £¬È»ºó¶à´ÎË¢ÐÂÒ³Ãæ £¬ÊÓ²ìÇëÇóÊÇ·ñÕý³£·Ö·¢¸øºó¶ËЧÀÍÆ÷¡£ÈôÊÇÒ»ÇÐÕý³£ £¬Ä㽫»á¿´µ½¶à¸öºó¶ËЧÀÍÆ÷½»ÌæÏìÓ¦ÇëÇóµÄÇéÐΡ£

ËÄ¡¢ÆäËû³£ÓÃÉèÖÃÑ¡Ï

³ýÁË»ù±¾µÄ¸ºÔØƽºâÉèÖà £¬Nginx»¹ÌṩÁËÐí¶àÆäËûµÄÉèÖÃÑ¡Ïî £¬ÒÔÖª×ã²î±ðµÄÐèÇó £¬ÒÔÏÂÊÇһЩ³£ÓõÄÉèÖÃÑ¡ÏîʾÀý£º

ȨÖØÉèÖãº

upstream backend {
 server backend1.example.com weight=3;
 server backend2.example.com weight=2;
 server backend3.example.com;
}

µÇ¼ºó¸´ÖÆ

ÔÚÕâ¸öʾÀýÖÐ £¬ÎÒÃÇͨ¹ýweight²ÎÊýÉèÖÃÁ˲î±ðºó¶ËЧÀÍÆ÷µÄȨÖØ £¬È¨ÖØÔ½¸ßµÄЧÀÍÆ÷½«·ÖÅɵ½¸ü¶àµÄÁ÷Á¿¡£

IP¹ÊÕÏתÒÆ£º

upstream backend {
 ip_hash;
 server backend1.example.com;
 server backend2.example.com;
 server backend3.example.com;
}

µÇ¼ºó¸´ÖÆ

ͨ¹ýÉèÖÃip_hash²ÎÊý £¬Nginx½«Æ¾Ö¤ÇëÇóµÄIPµØµã¾ÙÐйÊÕÏתÒÆ £¬¼´ÏàͬIPµÄÇëÇó½«×ÜÊDZ»·Ö·¢µ½Í³Ò»Ì¨ºó¶ËЧÀÍÆ÷¡£

¿µ½¡¼ì²é£º

http {
 upstream backend {
     server backend1.example.com max_fails=2 fail_timeout=30s;
     server backend2.example.com;
     server backend3.example.com;
 }
}

µÇ¼ºó¸´ÖÆ

ͨ¹ýÉèÖÃmax_failsºÍfail_timeout²ÎÊý £¬Nginx¿ÉÒÔ¶Ôºó¶ËЧÀÍÆ÷¾ÙÐпµ½¡¼ì²é £¬µ±Ä³¸öЧÀÍÆ÷Ò»Á¬Ê§°Ümax_fails´ÎÊýºó £¬½«ÔÝʱ±»±ê¼ÇΪ²»¿ÉÓà £¬fail_timeout²ÎÊýÖ¸¶¨ÁËÏ´ÎʵÑéµÄʱ¼ä¾àÀë¡£

½áÓ

NginxÐéÄâÖ÷»ú¸ºÔØƽºâÉèÖÃÊÇʵÏÖ¶àÓòÃûÊ¿Á¿·Ö·¢µÄÖ÷Òª»·½Ú £¬Í¨¹ýºÏÀíµÄÉèÖà £¬ÎÒÃÇ¿ÉÒÔÌá¸ßϵͳµÄ¿ÉÓÃÐÔºÍÐÔÄÜ¡£±¾ÎÄÌṩÁËÒ»¸ö»ù´¡µÄ¸ºÔØƽºâÉèÖÃʾÀý £¬²¢ÏÈÈÝÁËһЩ³£ÓõÄÉèÖÃÑ¡Ïî¡£¶ÁÕß¿ÉÒÔƾ֤ÏÖʵÐèÇó £¬ÎÞаµ÷½âÉèÖà £¬ÒÔÖª×ã×Ô¼ºµÄÓªÒµÐèÇó¡£Ï£Íû±¾ÎĶԸ÷ÈËÔÚÉèÖÃNginxÐéÄâÖ÷»ú¸ºÔØƽºâʱÓÐËù×ÊÖú¡£

ÒÔÉϾÍÊÇNginxÐéÄâÖ÷»ú¸ºÔØƽºâÉèÖà £¬ÊµÏÖ¶àÓòÃûÊ¿Á¿·Ö·¢µÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí £¬°æȨÕùÒéÓë±¾Õ¾ÎÞ¹Ø £¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í×ðÁú¿­Ê±ÂËÓÍ»úÍø¹Ù·½Ì¬¶È £¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ £¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢ £¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢ £¬ÇëÄúÁ¬Ã¦ÁªÏµ×ðÁú¿­Ê±ÊµÊ±ÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎå £¬9:30-18:30 £¬½ÚãåÈÕÐÝÏ¢

QR code
¡¾ÍøÕ¾µØͼ¡¿¡¾sitemap¡¿