尊龙凯时人生就是博

ÏêϸÏÈÈÝNginx·´ÏòÊðÀíЧÀÍÆ÷µÄÈÝÔÖ±¸·ÝÉèÖÃÒªÁì

nginx·´ÏòÊðÀíЧÀÍÆ÷µÄÈÝÔÖ±¸·ÝÉèÖÃÒªÁìÏê½â

¸ÅÊö

ÔÚ¹¹½¨WebÓ¦ÓõÄÇéÐÎÖÐ £¬¸ß¿ÉÓÃÐÔºÍÈÝÔÖ±¸·ÝÊÇÖÁ¹ØÖ÷ÒªµÄ ¡£Nginx×÷Ϊһ¿î¸ßÐÔÄܵķ´ÏòÊðÀíЧÀÍÆ÷ £¬ÓµÓÐÇ¿Ê¢µÄÈÝÔÖ±¸·ÝÉèÖù¦Ð§ £¬¿ÉÒÔÈ·±£ÏµÍ³ÔÚЧÀÍÆ÷¹ÊÕÏʱһÁ¬¿ÉÓà ¡£±¾ÎĽ«ÏÈÈÝNginx·´ÏòÊðÀíЧÀÍÆ÷µÄÈÝÔÖ±¸·ÝÉèÖÃÒªÁì £¬Ïêϸ˵Ã÷ÔõÑùʹÓñ¸·ÝЧÀÍÆ÷°ü¹ÜϵͳµÄ¸ß¿ÉÓÃÐÔ ¡£

×°ÖÃNginx

Ê×ÏÈ £¬ÐèҪȷ±£ÄãµÄЧÀÍÆ÷ÉÏÒѾ­×°ÖÃÁËNginx ¡£ÈôÊÇÄ㻹ûÓÐ×°ÖÃNginx £¬¿ÉÒÔͨ¹ýÒÔÏÂÏÂÁî¾ÙÐÐ×°Öãº

$ sudo apt-get update
$ sudo apt-get install nginx

µÇ¼ºó¸´ÖÆ

ÉèÖÃÖ÷ЧÀÍÆ÷

·­¿ªNginxµÄÖ÷ÉèÖÃÎļþ £¬Í¨³£Îª/etc/nginx/nginx.conf £¬¾ÙÐÐÈçÏÂÐ޸ģº

http {
 upstream backend {
     server primary_server:80;
     server backup_server:80 backup;
 }
 
 server {
     listen 80;
     server_name your_domain.com;

     location / {
         proxy_pass http://backend;
         proxy_set_header Host $host;
         proxy_set_header X-Real-IP $remote_addr;
     }
 }
}

µÇ¼ºó¸´ÖÆ

ÉÏÊöÉèÖÃÖÐ £¬ÎÒÃÇʹÓÃupstreamÖ¸Áî½ç˵ÁËÒ»¸öÃûΪbackendµÄ·´ÏòÊðÀíЧÀÍÆ÷µÄ¼¯Èº ¡£ÆäÖÐ £¬primary_serverÊÇÖ÷ЧÀÍÆ÷µÄµØµãÓë¶Ë¿Ú £¬backup_serverÊDZ¸·ÝЧÀÍÆ÷µÄµØµãÓë¶Ë¿Ú £¬²¢ÇÒʹÓÃÁËbackup²ÎÊýÌåÏÖ±¸·ÝЧÀÍÆ÷ ¡£Í¨¹ýÉèÖÃlocation / £¬Ö¸¶¨ÁËÇëÇóµÄת·¢µØµãΪhttp://backend ¡£

ÉèÖñ¸·ÝЧÀÍÆ÷

ÉèÖÃÎļþͬÑùΪ/etc/nginx/nginx.conf £¬ÈÔÈ»·­¿ªnginxµÄÖ÷ÉèÖÃÎļþ £¬ÐÞ¸ÄÈçÏ£º

http {
 upstream backend {
     server primary_server:80 backup;
     server backup_server:80;
 }
 
 server {
     listen 80;
     server_name your_domain.com;

     location / {
         proxy_pass http://backend;
         proxy_set_header Host $host;
         proxy_set_header X-Real-IP $remote_addr;
     }
 }
}

µÇ¼ºó¸´ÖÆ

ÔÚ±¸·ÝЧÀÍÆ÷ÖÐ £¬ÎÒÃǽ«primary_serverÓëbackup_serverµÄλÖöԵ÷ £¬ÕâÑùÔÚÖ÷ЧÀÍÆ÷å´»úʱ £¬ÇëÇ󽫻áת·¢ÖÁ±¸·ÝЧÀÍÆ÷ ¡£

ÉèÖÿµ½¡¼ì²é

ΪÁËÌá¸ßϵͳµÄ¿ÉÓÃÐÔ £¬ÎÒÃÇ¿ÉÒÔÉèÖÃNginx¾ÙÐпµ½¡¼ì²é £¬ÒÔ±ãÔÚЧÀÍÆ÷²»¿ÉÓÃʱʵʱÇл»µ½±¸·ÝЧÀÍÆ÷ ¡£·­¿ªNginxµÄÖ÷ÉèÖÃÎļþ £¬ÔöÌíÒÔÏÂÉèÖãº

http {
 upstream backend {
     server primary_server:80 backup;
     server backup_server:80;
     
     # ÆôÓÿµ½¡¼ì²é
     health_check;
     # ¼ì²é¾àÀëʱ¼ä
     check_interval 5s;
     # ʧ°Ü´ÎÊýãÐÖµ
     check_failure_threshold 3;
     # ¼ì²éµÄ³¬Ê±Ê±¼ä
     check_timeout 2s;
 }
 
 server {
     listen 80;
     server_name your_domain.com;

     location / {
         proxy_pass http://backend;
         proxy_set_header Host $host;
         proxy_set_header X-Real-IP $remote_addr;
     }
 }
}

µÇ¼ºó¸´ÖÆ

ÉÏÊöÉèÖÃÖÐ £¬ÎÒÃÇʹÓÃÁËhealth_checkÖ¸ÁîÆôÓÃÁË¿µ½¡¼ì²é¹¦Ð§ £¬²¢ÉèÖÃÁ˼ì²éµÄ¾àÀëʱ¼ä¡¢Ê§°Ü´ÎÊýãÐÖµºÍ³¬Ê±Ê±¼ä ¡£µ±Ö÷ЧÀÍÆ÷Ò»Á¬Ê§°Ü´ÎÊýµÖ´ïãÐֵʱ £¬Nginx½«»áÇл»µ½±¸·ÝЧÀÍÆ÷ ¡£

ÖØÆôNginxЧÀÍ

Íê³ÉÒÔÉÏÉèÖúó £¬Í¨¹ýÒÔÏÂÏÂÁîÖØÆôNginxЧÀÍʹÉèÖÃÉúЧ£º

$ sudo service nginx restart

µÇ¼ºó¸´ÖÆ

×ܽá

Nginx·´ÏòÊðÀíЧÀÍÆ÷ÌṩÁËÇ¿Ê¢µÄÈÝÔÖ±¸·ÝÉèÖù¦Ð§ £¬Ê¹ÏµÍ³ÔÚЧÀÍÆ÷¹ÊÕÏʱÒÀÈ»Äܹ»Ò»Á¬¿ÉÓà ¡£Í¨¹ýÉèÖÃÖ÷ЧÀÍÆ÷ºÍ±¸·ÝЧÀÍÆ÷¡¢¿µ½¡¼ì²éµÈ²Ù×÷ £¬¿ÉÒÔÈ·±£ÏµÍ³¸ß¿ÉÓÃÐÔ ¡£Ï£Íû±¾ÎÄËùÌṩµÄÐÅÏ¢¶ÔÄúÓÐËù×ÊÖú ¡£

ÒÔÉϾÍÊÇÏêϸÏÈÈÝNginx·´ÏòÊðÀíЧÀÍÆ÷µÄÈÝÔÖ±¸·ÝÉèÖÃÒªÁìµÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

ÁªÏµ尊龙凯时人生就是博

18523999891

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

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

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