¹¹½¨¸ßÐÔÄܵÄAPIÍø¹Ø£ºNginx Proxy ManagerµÄ×î¼Ñʵ¼ù
¹¹½¨¸ßÐÔÄܵÄAPIÍø¹Ø£ºNginx Proxy ManagerµÄ×î¼Ñʵ¼ù
Ëæ×ÅÊý×Ö»¯×ªÐ͵ÄÀ˳±Ï¯¾í¶øÀ´£¬Ô½À´Ô½¶àµÄÆóÒµ½«ÓªÒµ¿ª·Å¸øÍⲿ¿ª·¢Õß»òÏàÖúͬ°é£¬Ê¹µÃAPIÍø¹ØµÄÖ÷ÒªÐÔÈÕÒæ͹ÏÔ¡£APIÍø¹Ø×÷Ϊǰ¶ËЧÀ͵ÄÈë¿Ú£¬²»µ«ÐèÒªÌṩÇå¾²¿É¿¿µÄÊý¾Ý´«ÊäͨµÀ£¬»¹ÐèÒª¾ß±¸¸ßÐÔÄܺÍÀ©Õ¹ÐÔ£¬ÒÔÓ¦¶ÔÒ»Ö±ÔöÌíµÄÇëÇóÁ¿ºÍÓªÒµÐèÇó¡£Nginx Proxy Manager×÷Ϊһ¿îÇáÁ¿¼¶µÄ·´ÏòÊðÀí¹¤¾ß£¬¾ß±¸ÎÞа¡¢¸ßÐÔÄÜ¡¢¿ÉÀ©Õ¹µÈÓŵ㣬³ÉΪ¿ª·¢ÕßÃǹ¹½¨¸ßЧAPIÍø¹ØµÄÊ×Ñ¡¡£
±¾ÎĽ«·ÖÏíһЩʹÓÃNginx Proxy Manager¹¹½¨¸ßÐÔÄÜAPIÍø¹ØµÄ×î¼Ñʵ¼ù£¬²¢ÌṩÏêϸµÄ´úÂëʾÀý¡£
µÚÒ»²½£º×°ÖúÍÉèÖÃNginx Proxy Manager
Ê×ÏÈ£¬ÐèҪװÖÃNginx Proxy Manager²¢¾ÙÐлù±¾ÉèÖ᣿ÉÒÔͨ¹ýÔÚÏÂÁîÐÐÖÐÔËÐÐÒÔÏÂÏÂÁîÀ´×°ÖÃNginx Proxy Manager£º
sudo apt-get install nginx-proxy-manager
µÇ¼ºó¸´ÖÆ
×°ÖÃÍê³Éºó£¬ÐèÒª·¿ªNginx Proxy ManagerµÄÉèÖÃÎļþ¾ÙÐнøÒ»²½ÉèÖá£ÉèÖÃÎļþλÓÚ/etc/nginx-proxy-manager/config.json£¬¿ÉÒÔͨ¹ýÎı¾±à¼Æ÷·¿ª¾ÙÐб༡£
ÔÚÉèÖÃÎļþÖУ¬ÐèÒªÉèÖÃAPIÍø¹ØËù¼àÌýµÄ¶Ë¿Ú¡¢SSLÖ¤ÊéµÈÐÅÏ¢¡£ÒÔÏÂÊÇÒ»¸ö¼òÆÓµÄÉèÖÃʾÀý£º
{ "http": { "port": 80 }, "https": { "enabled": true, "port": 443, "ssl": { "key": "/path/to/ssl/key", "certificate": "/path/to/ssl/certificate" } } }
µÇ¼ºó¸´ÖÆ
ÔÚÉèÖÃÎļþÖУ¬¿ÉÒÔƾ֤ÏÖʵÐèÇó¾ÙÐнøÒ»²½µÄ¸öÐÔ»¯ÉèÖá£ÉèÖÃÍê³Éºó£¬ÉúÑIJ¢¹Ø±ÕÉèÖÃÎļþ¡£
µÚ¶þ²½£ºÊðÀíÉèÖÃ
Nginx Proxy ManagerµÄ½¹µã¹¦Ð§ÊÇ·´ÏòÊðÀí¡£ÔÚÉèÖÃÊðÀí֮ǰ£¬ÐèҪȷ±£ÒѾװÖÃÁËÏìÓ¦µÄЧÀͲ¢½«Æä׼ȷÉèÖá£
ÒÔÏÂÊÇÒ»¸öʾÀý£¬Õ¹Ê¾ÔõÑùͨ¹ýNginx Proxy Manager½«ÇëÇóÊðÀíµ½ÄÚ²¿µÄAPIЧÀÍÆ÷£º
{ "proxies": { "my_api": { "location": "/api", "upstream": "http://internal.api.server", "strip_path": "/api" } } }
µÇ¼ºó¸´ÖÆ
ÔÚÉÏÊöʾÀýÖУ¬ÎÒÃǽç˵ÁËÒ»¸öÃûΪmy_apiµÄÊðÀí£¬²¢ÉèÖÃÁËÊðÀíµÄλÖÃΪ/api¡£µ±ÊÕµ½À´×Ô¿Í»§¶ËµÄÇëÇóʱ£¬Nginx Proxy Manager»á½«ÇëÇóת·¢µ½http://internal.api.server¡£
³ýÁË»ù±¾µÄÊðÀíÉèÖÃÖ®Í⣬Nginx Proxy Manager»¹ÌṩÁËÐí¶àÆäËû¹¦Ð§£¬ÀýÈ縺ÔØƽºâ¡¢»º´æ¡¢Çå¾²ÈÏÖ¤µÈ¡£¿ÉÒÔƾ֤ÏêϸµÄÐèÇó¾ÙÐнøÒ»²½µÄÉèÖá£
µÚÈý²½£º¼à¿ØºÍÈÕÖ¾
ÔÚ¹¹½¨¸ßÐÔÄܵÄAPIÍø¹Øʱ£¬¼à¿ØºÍÈÕÖ¾ÊǺÜÊÇÖ÷ÒªµÄ¡£Nginx Proxy Manager¼¯³ÉÁËһЩ³£¼ûµÄ¼à¿ØºÍÈÕÖ¾¹¦Ð§£¬¿ÉÒÔ×ÊÖú¿ª·¢Õß×·×ÙÇëÇóÁ÷Á¿ºÍÐÔÄÜÆ¿¾±¡£
ÒÔÏÂÊÇÒ»¸öʾÀý£¬Õ¹Ê¾ÔõÑùÉèÖÃNginx Proxy ManagerµÄÈÕÖ¾¼Í¼¹¦Ð§£º
{ "logging": { "access_log": "/var/log/nginx/access.log", "error_log": "/var/log/nginx/error.log" } }
µÇ¼ºó¸´ÖÆ
ÔÚÉÏÊöʾÀýÖУ¬ÎÒÃǽ«»á¼ûÈÕÖ¾¼Í¼µ½/var/log/nginx/access.log£¬½«¹ýʧÈÕÖ¾¼Í¼µ½/var/log/nginx/error.log¡£
³ýÁËÈÕÖ¾¼Í¼֮Í⣬Nginx Proxy Manager»¹¿ÉÒÔÉèÖüà¿ØÖ¸±ê£¬ÀýÈçÇëÇóÊý¡¢ÏìӦʱ¼äµÈ¡£¿ÉÒÔͨ¹ýµÚÈý·½¹¤¾ß£¬ÈçGrafana¡¢PrometheusµÈÀ´¾ÙÐмà¿Ø¡£
µÚËIJ½£ºÇå¾²¼Ó¹Ì
ÔÚ¹¹½¨APIÍø¹Øʱ£¬Çå¾²ÐÔÊÇÖÁ¹ØÖ÷ÒªµÄ¡£Nginx Proxy ManagerÌṩÁËһЩÇå¾²¼Ó¹Ì¹¦Ð§£¬ÒÔ±£»¤APIÍø¹ØÃâÊܶñÒâ¹¥»÷ºÍÊý¾Ý鶵ÄΣº¦¡£
ÒÔÏÂÊÇһЩ³£¼ûµÄÇå¾²¼Ó¹Ì²½·¥£º
¿ªÆôSSL/TLS¼ÓÃÜ£ºÈ·±£ÇëÇóºÍÏìÓ¦µÄÊý¾Ý´«ÊäÊǼÓÃܵģ¬×èÖ¹Êý¾Ýй¶¡£
±ÜÃâDDoS¹¥»÷£ºÍ¨¹ýÉèÖÃIP°×Ãûµ¥¡¢ÏÞÖƲ¢·¢ÅþÁ¬ÊýµÈÊֶΣ¬ÓÐÓ÷ÀÓùDDoS¹¥»÷¡£
Çå¾²ÈÏÖ¤£ºÉèÖûùÓÚÁîÅÆ¡¢APIÃÜÔ¿¡¢OAuthµÈ·½·¨µÄÇå¾²ÈÏÖ¤£¬È·±£Ö»ÓÐÕýµ±Óû§Äܹ»»á¼ûAPI¡£
¿ÉÒÔƾ֤ÏêϸµÄÐèÇ󣬾ÙÐÐÎÞаµÄÇå¾²¼Ó¹ÌÉèÖá£
×ܽ᣺
±¾ÎÄÏÈÈÝÁËʹÓÃNginx Proxy Manager¹¹½¨¸ßÐÔÄÜAPIÍø¹ØµÄ×î¼Ñʵ¼ù£¬²¢ÌṩÁËһЩÏêϸµÄ´úÂëʾÀý¡£Nginx Proxy ManagerµÄÎÞаÐԺ͸ßÐÔÄÜʹÆä³ÉΪ¹¹½¨¸ßЧAPIÍø¹ØµÄÀíÏëÑ¡Ôñ¡£È»¶ø£¬ÐèҪעÖصÄÊÇ£¬Æ¾Ö¤²î±ðµÄ³¡¾°ºÍÐèÇ󣬿ÉÄÜÐèÒª¾ÙÐиöÐÔ»¯ÉèÖú͵÷ÓÅ¡£
ʹÓÃNginx Proxy Manager¹¹½¨¸ßÐÔÄܵÄAPIÍø¹Ø£¬¿ÉÒÔÌṩÇå¾²¡¢¿É¿¿¡¢¸ßÐÔÄܵÄÊý¾Ý´«ÊäͨµÀ£¬Öª×ãÒ»Ö±ÔöÌíµÄÇëÇóÁ¿ºÍÓªÒµÐèÇó¡£Ï£Íû±¾ÎĶԶÁÕßÔÚ¹¹½¨APIÍø¹ØʱÄܹ»ÌṩһЩ×ÊÖúºÍÖ¸µ¼¡£
ÒÔÉϾÍÊǹ¹½¨¸ßÐÔÄܵÄAPIÍø¹Ø£ºNginx Proxy ManagerµÄ×î¼Ñʵ¼ùµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡