×ðÁú¿­Ê±

NginxÔõÑùʵÏÖ¸ºÔØƽºâÉèÖÃ

NginxÔõÑùʵÏÖ¸ºÔØƽºâÉèÖà £¬ÐèÒªÏêϸ´úÂëʾÀý

СÐò£º

¸ºÔØƽºâÊÇÒ»ÖÖÔÚÍøÂçЧÀÍÆ÷ÖзÖÅÉÊÂÇ鸺ºÉµÄÒªÁì £¬Ê¹µÃ¶ą̀ЧÀÍÆ÷¿ÉÒÔЭͬ´¦Öóͷ£ÇëÇó £¬Ìá¸ßϵͳµÄ¿ÉÓÃÐÔºÍÐÔÄÜ ¡£ÔÚNginxÖÐ £¬ÎÒÃÇ¿ÉÒÔͨ¹ýÉèÖÃʵÏÖ¸ºÔØƽºâ £¬±¾ÎĽ«ÏÈÈÝÔõÑùʹÓÃNginx¾ÙÐиºÔØƽºâÉèÖà £¬²¢ÌṩÏêϸµÄ´úÂëʾÀý £¬Ï£Íû¶Ô¶ÁÕßÓÐËù×ÊÖú ¡£

Ò»¡¢Nginx¸ºÔØƽºâµÄ»ùÀ´Ô´Àí

Nginxͨ¹ýHTTP·´ÏòÊðÀíµÄ·½·¨ÊµÏÖ¸ºÔØƽºâ ¡£µ±¿Í»§¶Ë·¢ËÍÇëÇóʱ £¬Nginx×÷ΪÊðÀíЧÀÍÆ÷½«ÇëÇóת·¢¸øºǫ́µÄ¶ą̀ЧÀÍÆ÷ £¬ÔÙ½«Ð§ÀÍÆ÷´¦Öóͷ£µÄЧ¹û·µ»Ø¸ø¿Í»§¶Ë ¡£NginxÖ§³Ö¶àÖÖ¸ºÔØƽºâÕ½ÂÔ £¬°üÀ¨ÂÖѯ¡¢¼ÓȨÂÖѯ¡¢IP¹þÏ£¡¢×îÉÙÅþÁ¬ÊýµÈ ¡£

¶þ¡¢Nginx¸ºÔØƽºâµÄÉèÖÃÒªÁì

×°ÖÃNginx

Ê×ÏÈÐèÒªÔÚЧÀÍÆ÷ÉÏ×°ÖÃNginx ¡£ÏêϸװÖÃÒªÁì¿É²Î¿¼Nginx¹Ù·½Îĵµ ¡£

ÉèÖúǫ́ЧÀÍÆ÷

ÔÚʵÏÖ¸ºÔØƽºâ֮ǰ £¬ÐèÒªÏÈÔÚºǫ́׼±¸¶à¸öЧÀÍÆ÷ÓÃÓÚ´¦Öóͷ£ÇëÇó ¡£¿ÉÒÔÊǶą̀ÎïÀíЧÀÍÆ÷ £¬Ò²¿ÉÒÔÊÇͳһ̨ЧÀÍÆ÷µÄ¶à¸öÐéÄâÖ÷»ú ¡£

ÉèÖÃNginxÊðÀí

±à¼­NginxµÄÉèÖÃÎļþ £¬Ò»Ñùƽ³£Î»ÓÚ/etc/nginx/nginx.conf ¡£ÔÚhttpÄ£¿éÖÐÌí¼ÓÒÔÏ´úÂ룺

http {
    upstream backend {
        server backend1.example.com weight=1;
        server backend2.example.com weight=2;
    }

    server {
        listen 80;
        server_name example.com;

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

µÇ¼ºó¸´ÖÆ

ÉÏÊöÉèÖÃÖÐ £¬upstreamÒªº¦×Ö½ç˵ÁËÒ»×éºǫ́ЧÀÍÆ÷ £¬¿ÉÒÔƾ֤ÐèÇóÌí¼Ó»òɾ³ýЧÀÍÆ÷ ¡£ÆäÖÐ £¬backend1.example.comºÍbackend2.example.com¿ÉÒÔÌ滻ΪÏÖʵµÄЧÀÍÆ÷ÓòÃû»òIPµØµã ¡£weight²ÎÊý½ç˵ÁËÿ¸öЧÀÍÆ÷µÄȨÖØ £¬È¨ÖØÔ½¸ß £¬´¦Öóͷ£µÄÇëÇóÔ½¶à ¡£

ÖØÆôNginxЧÀÍ

ÉúÑÄÉèÖÃÎļþ²¢ÖØÆôNginxЧÀÍ £¬Ê¹ÉèÖÃÉúЧ ¡£

sudo systemctl restart nginx

µÇ¼ºó¸´ÖÆ

Èý¡¢Nginx¸ºÔØƽºâµÄʵÀýºÍЧ¹û

¼ÙÉèÓÐÁ½Ì¨Ð§ÀÍÆ÷backend1£¨192.168.1.100£©ºÍbackend2£¨192.168.1.200£© £¬ÆäÖÐbackend2µÄȨÖØÊÇbackend1µÄÁ½±¶ ¡£µ±Óпͻ§¶Ë·¢ËÍÇëÇóʱ £¬Nginx½«»áƾ֤ȨÖؾÙÐзַ¢ ¡£ÏêϸÉèÖÃÈçÏ£º

http {
    upstream backend {
        server 192.168.1.100 weight=1;
        server 192.168.1.200 weight=2;
    }

    server {
        listen 80;
        server_name example.com;

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

µÇ¼ºó¸´ÖÆ

ÔÚÒÔÉÏÉèÖÃÖÐ £¬µ±ÓÐ100¸öÇëÇó·¢Ë͵½Nginxʱ £¬backend1½«´¦Öóͷ£È¨ÖØΪ100/3¡Ö34¸öÇëÇó £¬¶øbackend2½«´¦Öóͷ£È¨ÖØΪ100/3*2¡Ö67¸öÇëÇó £¬´Ó¶øʵÏÖ¸ºÔØƽºâ ¡£

½áÂÛ£º

ͨ¹ýÒÔÉϵÄÉèÖúÍʾÀý´úÂë £¬ÎÒÃÇ¿ÉÒÔ¿´³ö £¬NginxµÄ¸ºÔØƽºâ¹¦Ð§ºÜÊÇÇ¿Ê¢ÇÒÒ×ÓÚÉèÖà ¡£ÎÞÂÛÊÇСÐÍÍøÕ¾ÕվɴóÐÍÓ¦ÓóÌÐò £¬¶¼¿ÉÒÔ½èÖúNginxʵÏָ߿ÉÓú͸ßÐÔÄܵĸºÔØƽºâ ¡£Ï£Íû±¾ÎĶÔÄúÃ÷È·Nginx¸ºÔØƽºâµÄÉèÖÃÒªÁìÓÐËù×ÊÖú ¡£

ÒÔÉϾÍÊÇNginxÔõÑùʵÏÖ¸ºÔØƽºâÉèÖõÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

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

18523999891

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

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

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