CN-122027625-A - Request forwarding optimization method based on Nginx
Abstract
The invention relates to the technical field of computer networks, in particular to a request forwarding optimization method based on Nginx. The method comprises the steps of analyzing request information to obtain request characteristic information, judging the request type according to the request characteristic information, if the request type is a common type, performing cache hit check, directly returning a cache response to a client when hit occurs, generating upstream request information when miss or failure occurs, selecting a forwarding strategy and generating Nginx configuration, inputting the upstream request information to a global load balancing module, distributing the upstream request information to a rear-end service node according to updated dynamic weight by the Nginx, processing the upstream request information by the rear-end service node, generating a response, and returning the response to the client. The invention can improve the forwarding efficiency, reduce unnecessary request forwarding by dynamically adjusting the forwarding strategy, and improve the response speed of the server, and has obvious advantages particularly in a high concurrency environment.
Inventors
- ZHAO MING
- ZHANG NAN
- WU YONGHONG
- SHEN SHEN
- MA CHEN
- CHEN HONGDA
- WANG ZHENGQI
- CAI HUIHUA
Assignees
- 北京航天计量测试技术研究所
Dates
- Publication Date
- 20260512
- Application Date
- 20251125
Claims (9)
- 1. The Nginx-based request forwarding optimization method is characterized by comprising the following steps of: s1, nginx receives a client request and analyzes request information to obtain request characteristic information; S2, judging a request type according to the request characteristic information, deleting a corresponding cache file and completing the request after the cache is invalid if the request type is a PURGE type, performing cache hit check if the request type is a common type, directly returning a cache response to a client when hit, and generating upstream request information when miss or invalidation occurs; S3, selecting a forwarding strategy and generating Nginx configuration according to the upstream request information, the server load state and the service requirement; S4, inputting the upstream request information into a global load balancing module, updating Nginx configuration, and distributing the upstream request information to a back-end service node according to the updated dynamic weight by the Nginx; s5, the back-end service node processes the upstream request information and then generates a response, and the response is returned to the client; And S6, updating a forwarding strategy, dynamic weight and a caching strategy required by the next round of client requests to form closed loop optimization.
- 2. The method for optimizing forwarding of Nginx-based request of claim 1 wherein the request message in step S1 comprises source IP, request header, request type.
- 3. The method for optimizing forwarding of a request based on nginnx as claimed in claim 1, wherein if the request type in step S2 is a normal type, performing cache hit check, and directly returning a cache response to the client when hit includes: s21, if the request type is a common type, performing cache hit check; S22, reading the cache file from the disk, and assembling a response head; S23, directly returning a cache response to the client side when hitting.
- 4. A method for optimizing forwarding of requests based on nginnx according to claim 3, wherein the inputting of the upstream request information to the global load balancing module in step S4, updating the nginnx configuration includes: S41, inputting the upstream request information to a global load balancing module for preliminary distribution; S42, the global load balancing module generates an access log and pushes the access log to a log stream system; s43, calculating the key indexes of the access log through a real-time stream processing module; s44, storing the access log key index, updating dynamic weight and updating Nginx configuration.
- 5. The method for optimizing forwarding of requests based on Nginx as claimed in claim 4, wherein the key indicators of the access log comprise health status of the server, response time and request amount.
- 6. The nginnx-based request forwarding optimization method according to claim 4, wherein the back-end service node in step S5 generates a response after processing the upstream request information, and returns the response to the client comprises: S51, the back-end service node processes the upstream request information and generates a response; S52, writing the response to be cached into the cache; and S53, summarizing the response, and returning the response to the client.
- 7. The method for optimizing request forwarding based on Nginx according to claim 4, wherein the load balancing module adopts a polling, minimum connection number and weight scheduling load balancing strategy.
- 8. An nginnx-based request forwarding optimization system, comprising: The Nginx module is used for receiving a client request and analyzing request information to obtain request characteristic information; the judging module is used for judging the request type according to the request characteristic information, deleting the corresponding cache file and completing the request after the cache is invalid if the request type is the PURGE type, carrying out cache hit check if the request type is the common type, directly returning a cache response to the client when hit, and generating upstream request information when miss or invalidation occurs; the selection module is used for selecting a forwarding strategy and generating Nginx configuration according to the upstream request information, the server load state and the service requirement; the first updating module is used for inputting the upstream request information into the global load balancing module, updating the Nginx configuration, and distributing the upstream request information to a back-end service node according to the updated dynamic weight by the Nginx; The processing module is used for generating a response after the back-end service node processes the upstream request information and returning the response to the client; and the second updating module is used for updating the forwarding strategy, the dynamic weight and the caching strategy required by the next round of client requests to form closed loop optimization.
- 9. An electronic device comprising a processor and a memory, the memory storing program instructions, wherein the processor executes the program instructions to implement an Nginx-based request forwarding optimization method of any one of claims 1 to 7.
Description
Request forwarding optimization method based on Nginx Technical Field The invention relates to the technical field of computer networks, in particular to a request forwarding optimization method based on Nginx. Background In modern internet architecture, nginx is widely used in a plurality of fields such as load balancing, reverse proxy, request forwarding, etc. With the continuous development of internet applications and services, web servers are faced with increasingly complex request forwarding requirements. However, existing nginnx forwarding mechanisms may have certain performance bottlenecks in certain specific scenarios, especially for high concurrent requests, where there is room for optimization of processing efficiency and forwarding accuracy. Conventional nginnx forwarding techniques rely mostly on static configuration, but these conventional approaches are less flexible in the face of dynamic requests or the need for forwarding based on specific conditions. Therefore, a new technical solution capable of improving the forwarding efficiency and flexibility of the nginnx request is urgently needed. Disclosure of Invention In view of the above-mentioned drawbacks of the prior art, the present invention aims to provide an nginix-based request forwarding optimization method, which solves the problems of performance bottleneck and flexibility, improves forwarding efficiency in a high concurrency environment, and can dynamically adjust forwarding strategies according to actual requirements, so as to optimize load balancing capability of a Web server. To achieve the above and other related objects, the present invention provides a method for optimizing forwarding of requests based on nginnx, including: s1, nginx receives a client request and analyzes request information to obtain request characteristic information; S2, judging a request type according to the request characteristic information, deleting a corresponding cache file and completing the request after the cache is invalid if the request type is a PURGE type, performing cache hit check if the request type is a common type, directly returning a cache response to a client when hit, and generating upstream request information when miss or invalidation occurs; S3, selecting a forwarding strategy and generating Nginx configuration according to the upstream request information, the server load state and the service requirement; S4, inputting the upstream request information into a global load balancing module, updating Nginx configuration, and distributing the upstream request information to a back-end service node according to the updated dynamic weight by the Nginx; s5, the back-end service node processes the upstream request information and then generates a response, and the response is returned to the client; And S6, updating a forwarding strategy, dynamic weight and a caching strategy required by the next round of client requests to form closed loop optimization. In an embodiment of the present invention, the request information in step S1 includes a source IP, a request header, and a request type. In an embodiment of the present invention, if the request type in step S2 is a normal type, performing cache hit check, and directly returning the cache response to the client when hit includes: s21, if the request type is a common type, performing cache hit check; S22, reading the cache file from the disk, and assembling a response head; S23, directly returning a cache response to the client side when hitting. In an embodiment of the present invention, inputting the upstream request information to the global load balancing module in step S4, and updating the nginnx configuration includes: S41, inputting the upstream request information to a global load balancing module for preliminary distribution; S42, the global load balancing module generates an access log and pushes the access log to a log stream system; s43, calculating the key indexes of the access log through a real-time stream processing module; s44, storing the access log key index, updating dynamic weight and updating Nginx configuration. In an embodiment of the present invention, the access log key indicators include server health status, response time, and request amount. In an embodiment of the present invention, the generating, by the backend service node, a response after processing the upstream request information, and returning the response to the client in step S5 includes: S51, the back-end service node processes the upstream request information and generates a response; S52, writing the response to be cached into the cache; and S53, summarizing the response, and returning the response to the client. In an embodiment of the present invention, the load balancing module uses a polling, minimum connection number, weight scheduling load balancing strategy. The invention also provides a request forwarding optimization system based on Nginx, which comprises the following steps: The Nginx