ÔõÑùʹÓÃNginx Proxy ManagerʵÏÖ¶ą̀ЧÀÍÆ÷µÄ¸ºÔØƽºâ
ÔõÑùʹÓÃNginx Proxy ManagerʵÏÖ¶ą̀ЧÀÍÆ÷µÄ¸ºÔØƽºâ
Nginx Proxy ManagerÊÇÒ»¸ö»ùÓÚNginx¿ª·¢µÄÊðÀíЧÀÍÆ÷ÖÎÀí¹¤¾ß£¬ËüÌṩÁËÒ»¸ö¼òÆÓÒ×ÓõÄWeb½çÃ棬¿ÉÒÔÀû±ãµØÉèÖúÍÖÎÀíNginxÊðÀíЧÀÍÆ÷¡£ÔÚÏÖʵӦÓÃÖУ¬ÎÒÃǾ³£ÐèÒª½«ÇëÇó·Ö·¢µ½¶ą̀ЧÀÍÆ÷ÉÏ£¬ÒÔʵÏÖ¸ºÔØƽºâºÍÌá¸ßϵͳµÄÐÔÄܺͿÉÓÃÐÔ¡£±¾ÎĽ«ÏÈÈÝÔõÑùʹÓÃNginx Proxy ManagerʵÏÖ¶ą̀ЧÀÍÆ÷µÄ¸ºÔØƽºâ£¬²¢ÌṩÏêϸµÄ´úÂëʾÀý¡£
°ì·¨1£º×°ÖúÍÉèÖÃNginx Proxy Manager
Ê×ÏÈ£¬ÎÒÃÇÐèҪװÖÃNginx Proxy Manager¡£¿ÉÒÔͨ¹ýÒÔÏÂÏÂÁîÔÚUbuntuϵͳÉÏ×°Öãº
sudo apt-get update sudo apt-get install -y nginx
µÇ¼ºó¸´ÖÆ
×°ÖÃÍê³Éºó£¬·¿ªÖնˣ¬ÊäÈëÒÔÏÂÏÂÁîÀ´¼ì²éNginxÊÇ·ñ×°ÖÃÀֳɣº
nginx -v
µÇ¼ºó¸´ÖÆ
½ÓÏÂÀ´£¬ÎÒÃÇÐèÒªÉèÖÃNginx Proxy Manager¡£ÔÚÖÕ¶ËÖÐÊäÈëÒÔÏÂÏÂÁî·¿ªNginxµÄÉèÖÃÎļþ£º
sudo nano /etc/nginx/nginx.conf
µÇ¼ºó¸´ÖÆ
ÔÚÉèÖÃÎļþÖÐÕÒµ½http²¿·Ö£¬ÔÚÆäÖÐÌí¼ÓÒÔÏÂÉèÖãº
upstream backend { server server1.example.com; server server2.example.com; } server { listen 80; server_name example.com; location / { proxy_pass http://backend; } }
µÇ¼ºó¸´ÖÆ
ÆäÖУ¬upstreamÖ¸Áî½ç˵Á˺ó¶ËЧÀÍÆ÷µÄ¼¯Èº£¬serverÖ¸Áî½ç˵ÁËÿ¸öºó¶ËЧÀÍÆ÷µÄµØµã¡£ÔÚÕâ¸öʾÀýÖУ¬ÎÒÃÇÉèÖÃÁËÁ½¸öºó¶ËЧÀÍÆ÷£¬»®·ÖΪserver1.example.comºÍserver2.example.com¡£proxy_passÖ¸ÁÇëÇóת·¢µ½ºó¶ËЧÀÍÆ÷µÄ¼¯ÈºbackendÉÏ¡£
ÉúÑIJ¢¹Ø±ÕÉèÖÃÎļþ£¬È»ºóÖØмÓÔØNginxÉèÖãº
sudo systemctl reload nginx
µÇ¼ºó¸´ÖÆ
°ì·¨2£ºÉèÖÃÓòÃûÖ¸ÏòNginx Proxy Manager
ÔÚÉÏÒ»²½µÄÉèÖÃÖУ¬ÎÒÃǼÙÉèÓòÃûΪexample.com¡£ÎÒÃÇÐèÒª½«ÓòÃûÖ¸ÏòNginx Proxy ManagerµÄЧÀÍÆ÷£¬ÒÔ±ãÇëÇó¿ÉÒÔͨ¹ýNginx¾ÙÐÐת·¢¡£ÏêϸÉèÖ÷½·¨¿ÉÒԲο¼ÓòÃû×¢²áÉÌÌṩµÄÎĵµ»òÕßÁªÏµËûÃǵĿͷþ¡£
°ì·¨3£ºÉèÖÃNginx Proxy Manager
ÔÚä¯ÀÀÆ÷Öлá¼ûhttp://example.com£¬·¿ªNginx Proxy ManagerµÄWeb½çÃæ¡£Ê״εǼÐèÒªÉèÖÃÖÎÀíÔ±Õ˺źÍÃÜÂë¡£
µÇ¼ºó£¬µã»÷×ó²àµ¼º½À¸ÖеĔHosts”£¬½øÈëÖ÷»úÁбíÒ³Ãæ¡£µã»÷”Add Host”°´Å¥£¬Ìí¼ÓеÄÖ÷»ú¡£ÔÚµ¯³öµÄ¶Ô»°¿òÖУ¬ÌîдÖ÷»úÃû³ÆºÍÖ÷»úµØµã£¬È»ºóµã»÷”Save”¡£
½ÓÏÂÀ´£¬µã»÷×ó²àµ¼º½À¸ÖеĔServers”£¬½øÈëЧÀÍÆ÷ÁбíÒ³Ãæ¡£µã»÷”Add Server”°´Å¥£¬Ìí¼ÓеÄЧÀÍÆ÷¡£ÔÚµ¯³öµÄ¶Ô»°¿òÖУ¬Ñ¡ÔñÖ÷»úºÍ¶Ë¿Ú£¬È»ºóµã»÷”Save”¡£
Öظ´ÉÏÊö°ì·¨£¬Ìí¼ÓÐèÒªµÄЧÀÍÆ÷ºÍÖ÷»ú¡£
°ì·¨4£º²âÊÔ¸ºÔØƽºâ
ÏÖÔÚ£¬ÎÒÃÇÒѾÉèÖúÃÁËNginx Proxy ManagerºÍºó¶ËЧÀÍÆ÷¡£¿ÉÒÔͨ¹ýÒÔÏ·½·¨²âÊÔ¸ºÔØƽºâÊÇ·ñÕý³£ÊÂÇ飺
·¿ªWebä¯ÀÀÆ÷£¬ÊäÈëÓòÃûhttp://example.com£¬È»ºó¶à´ÎË¢ÐÂÒ³Ã棬ÊÓ²ìÇëÇóÊÇ·ñ·Ö·¢µ½²î±ðµÄºó¶ËЧÀÍÆ÷ÉÏ¡£
ÔÚÖÕ¶ËÖÐʹÓÃÏÂÁîcurl http://example.com¶à´Î·¢ËÍÇëÇó£¬ÊÓ²ìÏìÓ¦ÊÇ·ñÀ´×Ô²î±ðµÄºó¶ËЧÀÍÆ÷¡£
ÈôÊÇÇëÇó±»Àֳɵطַ¢µ½²î±ðµÄºó¶ËЧÀÍÆ÷ÉÏ£¬ËµÃ÷¸ºÔØƽºâÒѾÀÖ³ÉÉèÖá£
×ܽá
±¾ÎÄÏÈÈÝÁËÔõÑùʹÓÃNginx Proxy ManagerʵÏÖ¶ą̀ЧÀÍÆ÷µÄ¸ºÔØƽºâ£¬²¢ÌṩÁËÏêϸµÄ´úÂëʾÀý¡£Í¨¹ýNginx Proxy ManagerµÄ¼òÆÓÒ×ÓõÄWeb½çÃ棬¿ÉÒÔÀû±ãµØÉèÖúÍÖÎÀíNginxÊðÀíЧÀÍÆ÷£¬ÊµÏÖ¸ºÔØƽºâºÍÌá¸ßϵͳµÄÐÔÄܺͿÉÓÃÐÔ¡£Çëƾ֤ÏÖʵÐèÇó¾ÙÐÐÉèÖú͵÷½â£¬ÒÔ˳ӦÄúµÄÓ¦Óó¡¾°¡£
ÒÔÉϾÍÊÇÔõÑùʹÓÃNginx Proxy ManagerʵÏÖ¶ą̀ЧÀÍÆ÷µÄ¸ºÔØƽºâµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡