How to dynamically load HTTP routing in NGINX from your web page?

I followed the Web Frameworks test and noticed that some web structures suffer from the same performance penalty because they do HTTP routing within the structure itself and do not use the high-performance NGINX HTTP server for routing.

For example, in a Flask python framework, it could be:

@app.route('/add', methods=['POST']) def add_entry(): ... 

Which makes your application much easier than running it directly in the NGINX configuration file, for example:

 server { listen 80; server_name example.com; location /add { ... // defer to Flask (python) app } 

Question How can you improve the performance of NGINX's built-in HTTP routing (using your own NGINX configuration file to define routing), as well as simplify application development by specifying HTTP routing inside your web framework?

Is there a way to dynamically load HTTP routing into NGINX from INSERT_NAME_OF_YOUR_WEBFRAMEWORK?

+4
source share
1 answer

I do not know the finished library. But itโ€™s quite easy to write a script that generates the Nginx configuration file from the applicationโ€™s routes (for example, during application installation). This file can be included in the main server configuration using the "include" command in the Nginx configuration:

 server { listen 80; server_name example.com; include /path/to/application/routes.conf } 
+2
source

Source: https://habr.com/ru/post/1479383/


All Articles