Method for realizing nginx automatic proxy in micro-service scene

Through the automated configuration mechanism integrated with Nacos services, the cumbersome problem of static configuration update of Nginx agents in the microservice architecture is solved, automated service discovery and proxy configuration are realized, and system stability and work efficiency are improved.

CN119172428APending Publication Date: 2024-12-20BEIYIN FINANCIAL TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411332790.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-24
Publication Date
2024-12-20

AI Technical Summary

Technical Problem

In the microservice architecture, the existing technology relies on static configuration to update the Nginx proxy, which causes administrators to need to manually operate the configuration files, which are prone to errors and cumbersome to update when the service changes dynamically, affecting system stability.

Method used

Through in-depth integration with Nacos services, basic parameter configuration, load subscription configuration and automatic load update mechanism are adopted to realize the automated configuration and service discovery of Nginx agents, reduce manual intervention, and automatically update Nginx configuration files.

Benefits of technology

It realizes automated service discovery and proxy configuration without manual intervention, improves work efficiency, ensures real-time and accuracy of service agents, reduces problems caused by manual configuration errors, and improves system stability and availability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119172428A_ABST
    Figure CN119172428A_ABST
Patent Text Reader

Abstract

The invention discloses a method for realizing nginx automatic proxy in a micro-service scene. The proxy method comprises the following steps: configuring based on basic parameters; loading subscription configuration; and related applications are automatically loaded and updated. And through deep integration with the Nacos service, automatic service discovery and proxy configuration are realized. According to the technical scheme, the related information of the gateway service can be automatically subscribed and obtained, the related information is timely updated to the Nginx configuration file, manual intervention is not needed in the whole process, and the working efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of microservice architecture, and in particular to a method for realizing nginx automatic proxy in a microservice scenario. Background Art

[0002] With the rapid advancement of information technology, microservice architecture has gradually become the mainstream choice for building modern applications. The core idea of ​​this architectural pattern is to split a large and complex software system into a series of small, independent service units. Each service focuses on performing a specific business function and can be deployed, expanded, and maintained independently. This design not only improves the flexibility and scalability of the system, but also enables each service to respond to changes and needs more efficiently.

[0003] The introduction of microservice architecture is not without challenges. While achieving service independence and flexibility, it also brings some new problems, especially in terms of service discovery and load balancing. Service discovery refers to the process of quickly and accurately finding the required service among many microservices, while load balancing involves how to reasonably distribute requests among multiple service instances to ensure system performance and stability.

[0004] To solve these problems, the most commonly used microservice architecture in China is the "gateway" component in spring cloud alibaba as a gateway. This gateway is responsible for service discovery and load balancing. It can identify and locate other services in the microservice group and route requests to these services appropriately. However, the gateway service is usually not directly exposed to the public network to avoid potential security risks and unnecessary network load.

[0005] Disadvantages of existing technology:

[0006] Statically configure manual update policy

[0007] In the application environment of microservice architecture, Nginx is often used as a proxy for service interfaces. In this setting, the traditional static configuration update method requires the administrator to know the IP address and port information of each microservice in advance. Then, the administrator needs to manually edit the Nginx configuration file to accurately add or adjust the proxy rules.

[0008] This process involves direct manipulation of the Nginx configuration file, which requires the administrator to have certain technical knowledge and carefulness, because any configuration error may cause the proxy function to malfunction, thus affecting the normal operation of the service.

[0009] With the dynamic changes of microservice instances, such as the deployment of new services, the removal of old services, or the change of service ports, this manual configuration update method is particularly cumbersome. Whenever such changes occur, administrators must re-edit the configuration files and ensure that all changes are correct.

[0010] After completing the configuration update, in order to ensure that the new proxy rules can take effect, you need to restart the Nginx service. This process is not only time-consuming but also error-prone, especially in large or complex microservice architectures, where frequent changes in services make management more difficult.

[0011] 2.2 Intranet F5 load strategy

[0012] The method of using Nginx to proxy F5 and then having F5 load each service port is to use two different levels of load balancers to improve the overall performance and manageability of the system.

[0013] As the first-tier proxy, Nginx handles HTTP requests from the outside. It is responsible for the initial load balancing, forwarding requests to the F5 device, and handling tasks such as SSL termination and static content caching. As the second-tier load balancer, the F5 device receives requests from Nginx and distributes them to the backend service instances according to preset policies (such as polling, minimum number of connections, response time, etc.).

[0014] Although this configuration requires the administrator to manually update the Nginx configuration file to reflect changes in the backend service, F5 manages the load balancing of the backend service relatively independently, reducing dependence on Nginx. Summary of the invention

[0015] In view of the above problems, the present invention is proposed to provide a method for implementing nginx automatic proxy in a microservice scenario that overcomes the above problems or at least partially solves the above problems.

[0016] According to one aspect of the present invention, a method for implementing nginx automatic proxy in a microservice scenario is provided, and the proxy method includes:

[0017] Based on basic parameter configuration;

[0018] Load subscription configuration;

[0019] Automatic load update related applications.

[0020] Optionally, the basic parameter configuration specifically includes:

[0021] The basic parameter configuration uses the nginx include method to configure a separate file for the application that needs to be loaded, and configure the corresponding nacos parameter service parameters.

[0022] Optionally, the configured corresponding nacos parameter service parameters include username username, password password, server address serverAddr and namespace nameSpace.

[0023] Optionally, the loading subscription configuration specifically includes:

[0024] Load the subscription configuration, the application reads the specified configuration file *.conf, the application parses the corresponding parameters above, subscribes to the service IP port related information of the specified name from the specified configuration center nacos, and updates the server load configuration of the read configuration file. After completion, call the system command to update the nginx service.

[0025] Optionally, the automatic load update related applications specifically include:

[0026] Background scheduled tasks, long rotation training to query the relevant information of all subscribed services, after the query, continuously compare the differences between the obtained information and the existing information, if any differences are found, update the configuration file, call the system command to update the nginx service, and apply the subscription to the nacos service change event. When the nacos control console has a manual offline service, the service of the subscribed change event actively updates the configuration file and updates the nginx service.

[0027] Optionally, the basic parameter configuration also includes:

[0028] The nacos parameter service parameters are used to communicate with the nacos server to obtain and apply configuration information;

[0029] The application provides a management interface for users to generate the actual configuration file in the above example and upload it to the corresponding nginx server specified directory.

[0030] The present invention provides an nginx automatic proxy method in a microservice scenario, the proxy method comprising: configuring based on basic parameters; loading subscription configuration; and automatically updating related applications. Through deep integration with Nacos services, automated service discovery and proxy configuration are achieved. It is possible to automatically subscribe to and obtain relevant information of gateway services, and update relevant information to the Nginx configuration file in a timely manner. The entire process does not require manual intervention, thereby improving work efficiency.

[0031] The above description is only an overview of the technical solution of the present invention. In order to more clearly understand the technical means of the present invention, it can be implemented according to the contents of the specification. In order to make the above and other purposes, features and advantages of the present invention more obvious and easy to understand, the specific implementation methods of the present invention are listed below. BRIEF DESCRIPTION OF THE DRAWINGS

[0032] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative work.

[0033] Figure 1 A schematic diagram of basic parameter configuration provided by an embodiment of the present invention;

[0034] Figure 2 A schematic diagram of a loading subscription configuration provided by an embodiment of the present invention;

[0035] Figure 3 A schematic diagram of automatic updating provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0036] The exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided to enable a more thorough understanding of the present disclosure and to fully convey the scope of the present disclosure to those skilled in the art.

[0037] The terms "comprises" and "having" and any variations thereof in the description embodiments, claims and drawings of the present invention are intended to cover non-exclusive inclusions, for example, including a series of steps or units.

[0038] The technical solution of the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments.

[0039] This solution is divided into two steps. The first step is based on basic parameter configuration, the second step is to load subscription configuration, and the third step is to automatically load update related applications.

[0040] The first step is to configure the basic parameters. The basic parameter configuration uses the nginx include method to configure a separate file for the application that needs to be loaded, and configure the corresponding nacos parameter service parameters, including username, password, serverAddr, and nameSpace.

[0041] The second step is to load the subscription configuration. The application reads the specified configuration file *.conf, parses the corresponding parameters above, subscribes to the service IP port related information of the specified name from the specified configuration center nacos, and performs server load update configuration for the read configuration file. After completion, call the system command to update the nginx service.

[0042] The third step is the background scheduled task, which queries the relevant information of all subscribed services in a long rotation. After the query, it continuously compares the differences between the obtained information and the existing information. If differences are found, the configuration file is updated, the system command is called to update the nginx service, and the application subscribes to the nacos service change event. When the nacos control console has a manual offline service, the service of the subscribed change event actively updates the configuration file and updates the nginx service.

[0043] like Figure 1 As shown, basic parameter configuration:

[0044] In this process, the nginx include method is used. This method stores the application configuration that needs to be loaded in a separate file instead of setting it directly in the main configuration file of nginx. This makes it easy to modify and update the configuration of a specific application.

[0045] Configure a separate file for each application that needs to be loaded. This file contains all the relevant configuration information of the application. You need to use the custom declaration configuration parameter method to configure the corresponding nacos parameter service parameters, including username, password, serverAddr, and nameSpace. These parameters will be used to communicate with the nacos server to obtain and apply configuration information.

[0046] The application provides a management interface for users to generate the actual configuration file in the above example and upload it to the corresponding nginx server specified directory.

[0047] like Figure 2 As shown, load the subscription configuration:

[0048] The application will traverse all configuration files, that is, the configuration files configured in the first step. These files usually have a .conf extension. For each configuration file, the application will parse the parameters, including service name, IP address, and port information. These parameters will be used to interact with the configuration center nacos.

[0049] The application will connect to the specified configuration center nacos and subscribe to the service with the specified name according to the previously parsed parameters. By subscribing to the service, the application can obtain the latest service IP port related information.

[0050] Once the application successfully subscribes to the service with the specified name, it will update the server load configuration in the configuration file it reads. Dynamically update its internal server load balancing configuration. This ensures that the application can intelligently distribute requests to different servers based on the current service status, thereby improving system availability and performance.

[0051] When all configuration files are updated and the load balancing configuration is complete, the application calls the system command to update the nginx service.

[0052] like Figure 3 As shown, automatically update:

[0053] In this step, the system will perform polling queries for a long time to obtain relevant information of all subscribed services. This process is continuous to ensure that we can obtain the latest service information in real time.

[0054] After the query is completed, the system will compare the information. It will compare the newly obtained information with the existing information to see if there are any differences.

[0055] If different information is found during this process, the system will update the configuration file to ensure that all settings are up to date and then call the system command to update the nginx service.

[0056] The system supports subscribing to nacos service change events. When the nacos control console manually shuts down the service, the system can also respond in a timely manner. It will actively update the configuration file and update the nginx service to ensure that the service is always in the best state.

[0057] Beneficial effects:

[0058] 1. The present invention can automatically subscribe to and obtain relevant information of the gateway service, and update the information to the Nginx configuration file in a timely manner. When a new service is registered to Nacos, the software will automatically subscribe to the information of these services, including the address and port of the service, and update the information to the Nginx configuration file. No manual intervention is required, which reduces the workload of manual configuration and improves work efficiency.

[0059] 2. The present invention can monitor the service status changes in Nacos in real time, and once a change is found, it will immediately update the proxy load information of Nginx. This fast response mechanism ensures the real-time and accuracy of the service proxy, and even if the service status changes, it will not affect the normal operation of the service.

[0060] 3. Through automated service discovery and proxy configuration, Nginx forwards requests to the correct service based on the latest configuration information. The dynamic configuration mechanism reduces problems caused by manual configuration errors and improves system stability and availability.

[0061] The above specific implementation methods further illustrate the objectives, technical solutions and beneficial effects of the present invention in detail. It should be understood that the above are only specific implementation methods of the present invention and are not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.

Claims

1. A method for implementing nginx automatic proxy in a microservice scenario, characterized in that: The proxy method includes: Based on basic parameter configuration; Load subscription configuration; Automatic load update related applications.

2. According to the method for implementing nginx automatic proxy in a microservice scenario according to claim 1, it is characterized in that: The basic parameter configuration specifically includes: The basic parameter configuration uses the nginx include method to configure a separate file for the application that needs to be loaded, and configure the corresponding nacos parameter service parameters.

3. According to a method for implementing nginx automatic proxy in a microservice scenario according to claim 2, it is characterized in that: The configured corresponding nacos parameter service parameters include username username, password password, server address serverAddr and namespace nameSpace.

4. According to a method for implementing nginx automatic proxy in a microservice scenario according to claim 1, it is characterized in that: The loading subscription configuration specifically includes: Load the subscription configuration, the application reads the specified configuration file *.conf, the application parses the corresponding parameters above, subscribes to the service IP port related information of the specified name from the specified configuration center nacos, and updates the server load configuration of the read configuration file. After completion, call the system command to update the nginx service.

5. According to a method for implementing nginx automatic proxy in a microservice scenario according to claim 1, it is characterized in that: The automatic load update related applications specifically include: Background scheduled tasks, long rotation training to query the relevant information of all subscribed services, after the query, continuously compare the differences between the obtained information and the existing information, if any differences are found, update the configuration file, call the system command to update the nginx service, and apply the subscription to the nacos service change event. When the nacos control console has a manual offline service, the service of the subscribed change event actively updates the configuration file and updates the nginx service.

6. According to a method for implementing nginx automatic proxy in a microservice scenario according to claim 2, it is characterized in that: The basic parameter configuration also includes: The nacos parameter service parameters are used to communicate with the nacos server to obtain and apply configuration information; The application provides a management interface for users to generate the actual configuration file in the above example and upload it to the corresponding nginx server specified directory.