Other OpenResty features

OpenResty comes with many Lua scripts that can be useful to enhance nginx. Some developers are even using it to serve their data directly.

If you look at the components page at http://openresty.org/en/components.html, you will find some useful tools to have nginx interact with databases, cache servers, and so on. There's also a website for the community to publish OpenResty components, refer to https://opm.openresty.org/.

If you are using OpenResty in front of your Flask microservices, there will probably be other use cases where you can transfer some code that's in the Flask app to a few lines of Lua in OpenResty. The goal should not be to move the app's logic to OpenResty, but rather to leverage the web server to do anything that can be done before or after your Flask app is called.

For instance, if you are using a Redis or a Memcache server to cache some of your GET resources, you can directly call them from Lua to add or fetch a cached version for a given endpoint. The srcache-nginx-module (https://github.com/openresty/srcache-nginx-module) is an implementation of such a behavior and will reduce the number of GET calls made to your Flask apps if you can cache them.

To conclude this section about web application firewalls, OpenResty is a powerful nginx distribution that can be used to create a simple WAF to protect your microservices. It also offers abilities that go beyond firewalling. In fact, if you adopt OpenResty to run your microservices, it opens a whole new world of possibilities, thanks to Lua.

The next section that ends this chapter will focus on what can be done at the code level to protect your microservices.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset