ʹÓÃNginx Proxy ManagerʵÏÖAPIÍø¹ØµÄÈÏÖ¤ÓëÊÚȨ
ʹÓÃNginx Proxy ManagerʵÏÖAPIÍø¹ØµÄÈÏÖ¤ÓëÊÚȨ
×÷ΪÏÖ´ú»¥ÁªÍøÓ¦Óÿª·¢ÖеÄÖ÷Òª×é³É²¿·Ö£¬APIÍø¹ØÔÚÌṩ½Ó¿ÚŲÓõÄͬʱ£¬Ò²ÐèÒª°ü¹Ü½Ó¿ÚµÄÇå¾²ÐÔ¡£ÆäÖУ¬ÈÏÖ¤ÓëÊÚȨÊÇAPIÍø¹Ø²»¿É»òȱµÄ¹¦Ð§£¬ÓÃÓÚÑéÖ¤ÇëÇóÕßµÄÉí·Ý²¢ÊÚÓè»á¼ûȨÏÞ¡£±¾ÎĽ«ÏÈÈÝÔõÑùʹÓÃNginx Proxy ManagerʵÏÖAPIÍø¹ØµÄÈÏÖ¤ÓëÊÚȨ£¬²¢ÌṩÏêϸµÄ´úÂëʾÀý¡£
Ò»¡¢Ê²Ã´ÊÇNginx Proxy Manager
Nginx Proxy ManagerÊÇ»ùÓÚNginxµÄ·´ÏòÊðÀíºÍ¸ºÔØƽºâµÄÖÎÀí¹¤¾ß¡£ËüÌṩÁËÒ»¸ö¿ÉÊÓ»¯µÄÖÎÀí½çÃ棬Àû±ãÓû§ÉèÖúÍÖÎÀíNginxµÄÊðÀí¹æÔò¡£Nginx Proxy Manager¿ÉÒÔͨ¹ýÉèÖùæÔò¶ÔÇëÇó¾ÙÐÐת·¢£¬²¢Ö§³ÖÌí¼Ó×Ô½ç˵ÖÐÑë¼þÀ©Õ¹NginxµÄ¹¦Ð§¡£
¶þ¡¢ÈÏÖ¤ÓëÊÚȨ
ÔÚAPIÍø¹ØÖУ¬ÈÏÖ¤ÓëÊÚȨÊÇÒªº¦µÄÇå¾²²½·¥¡£ÈÏÖ¤ÓÃÓÚÑéÖ¤ÇëÇóÕßµÄÉí·Ý£¬Í¨³£½ÓÄÉAPIÃÜÔ¿¡¢Óû§ÃûÃÜÂëµÈ·½·¨¡£ÊÚȨÔòÊÇÔÚÈÏ֤ͨʺ󣬶ÔÇëÇóÕßµÄȨÏÞ¾ÙÐÐÅжϣ¬¾öÒéÊÇ·ñÔÊÐí»á¼ûij¸ö½Ó¿Ú¡£
Èý¡¢Ê¹ÓÃNginx Proxy ManagerʵÏÖÈÏÖ¤ÓëÊÚȨ
×°ÖÃNginx Proxy Manager
Ê×ÏÈ£¬ÎÒÃÇÐèÒªÔÚЧÀÍÆ÷ÉÏ×°ÖÃNginx Proxy Manager¡£¿ÉÒÔͨ¹ýÒÔÏÂÏÂÁî×°Öãº
$ sudo apt-get install nginx $ sudo apt-get install npm $ sudo npm install -g npx $ sudo npx create-npx npx
µÇ¼ºó¸´ÖÆ
ÉèÖÃÈÏÖ¤
ÔÚNginx Proxy ManagerµÄÖÎÀí½çÃæÉÏ£¬ÕÒµ½¶ÔÓ¦µÄÊðÀí¹æÔòÉèÖÃÏÔÚÖÐÑë¼þÉèÖÃÖÐÌí¼ÓÈÏÖ¤ÖÐÑë¼þ¡£ÈÏÖ¤ÖÐÑë¼þ¿ÉÒÔƾ֤ÇëÇóÕßÌṩµÄÉí·ÝÐÅÏ¢¾ÙÐÐÑéÖ¤¡£ÒÔÏÂÊÇÒ»¸öʹÓÃAPIÃÜÔ¿¾ÙÐÐÈÏÖ¤µÄʾÀý´úÂ룺
location /api { auth_basic "API Authentication"; auth_basic_user_file /etc/nginx/.htpasswd; proxy_pass http://backend; }
µÇ¼ºó¸´ÖÆ
ÔÚÉÏÊö´úÂëÖУ¬auth_basicÓÃÓÚÉèÖÃÈÏÖ¤ÌáÐÑÐÅÏ¢£¬auth_basic_user_fileÓÃÓÚÖ¸¶¨ÉúÑÄAPIÃÜÔ¿µÄÎļþ¡£Æ¾Ö¤ÏÖʵÐèÒª£¬¿ÉÒÔ×Ô½ç˵ÈÏÖ¤·½·¨£¬²¢Ìí¼ÓÏìÓ¦µÄÑéÖ¤Âß¼¡£
ÉèÖÃÊÚȨ
ÊÚȨµÄʵÏÖ·½·¨ÓëÈÏÖ¤ÀàËÆ£¬Ò²ÊÇÔÚÊðÀí¹æÔòÉèÖÃÏîµÄÖÐÑë¼þÉèÖÃÖÐÌí¼ÓÊÚȨÖÐÑë¼þ¡£ÒÔÏÂÊÇÒ»¸ö¼òÆÓµÄÊÚȨʾÀý´úÂ룺
location /api { auth_basic "API Authentication"; auth_basic_user_file /etc/nginx/.htpasswd; proxy_pass http://backend; if ($http_token != "123456") { return 403; } }
µÇ¼ºó¸´ÖÆ
ÔÚÉÏÊö´úÂëÖУ¬Í¨¹ýÅжÏÇëÇóÖÐÊÇ·ñ°üÀ¨×¼È·µÄ»á¼ûÁîÅÆ£¨token£©£¬¾öÒéÊÇ·ñ·µ»Ø403¹ýʧ£¨¼´ÎÞȨÏÞ£©¡£Æ¾Ö¤ÏÖʵÐèÒª£¬¿ÉÒÔ×Ô½ç˵ÊÚȨ·½·¨£¬²¢Ìí¼ÓÏìÓ¦µÄÊÚȨÂß¼¡£
ËÄ¡¢×ܽá
±¾ÎÄÏÈÈÝÁËʹÓÃNginx Proxy ManagerʵÏÖAPIÍø¹ØµÄÈÏÖ¤ÓëÊÚȨµÄÒªÁ죬²¢ÌṩÁËÏêϸµÄ´úÂëʾÀý¡£Í¨¹ýÉèÖÃÈÏÖ¤ºÍÊÚȨÖÐÑë¼þ£¬ÎÒÃÇ¿ÉÒÔÎÞаµØƾ֤ӪҵÐèÇ󣬶ÔAPIÇëÇó¾ÙÐÐÉí·ÝÑéÖ¤ºÍȨÏÞ¿ØÖÆ£¬°ü¹Ü½Ó¿ÚŲÓõÄÇå¾²ÐÔ¡£Ï£Íû±¾ÎĶÔÄúÃ÷È·ºÍʵ¼ùAPIÍø¹ØµÄÈÏÖ¤ÓëÊÚȨÓÐËù×ÊÖú¡£
ÒÔÉϾÍÊÇʹÓÃNginx Proxy ManagerʵÏÖAPIÍø¹ØµÄÈÏÖ¤ÓëÊÚȨµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡