Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is openResty?

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains "what is openResty". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "what is openResty?"

1. What is it?

OpenResty ®is a high-performance Web platform based on Nginx and Lua, which integrates a large number of excellent Lua libraries, third-party modules, and most dependencies. It is used to conveniently build dynamic Web applications, Web services and dynamic gateways that can handle ultra-high concurrency and high scalability.

OpenResty ®effectively turns Nginx into a powerful general-purpose Web application platform by bringing together a variety of well-designed Nginx modules (mainly developed by the OpenResty team). In this way, Web developers and system engineers can use Lua scripting language to mobilize various C and Lua modules supported by Nginx to quickly build a high-performance Web application system capable of concurrent connections on a single machine of 10K or more than 1000K.

The goal of OpenResty ®is to have your Web service run directly inside the Nginx service, taking full advantage of Nginx's non-blocking IPUP O model to provide consistent, high-performance responses not only to HTTP client requests, but even to remote backends such as MySQL, PostgreSQL, Memcached, and Redis.

2. How to use it? ①, installation

For some common Linux distributions (Ubuntu, Debian, CentOS, RHEL, Fedora, OpenSUSE, Alpine, and Amazon Linux), OpenResty ®provides an official precompiled package. Make sure you install it in this way first.

For Mac OS X or macOS users, it is highly recommended that you install OpenResty using the homebrew package management tool. You can use the following command directly:

Brew install openresty/brew/openresty

If you previously installed OpenResty from homebrew/nginx, please execute:

Brew untap homebrew/nginx

If you haven't downloaded the source package for OpenResty, go to the Download page to download it.

First, you can install and build OpenResty based on the following example.

Tar-xzvf openresty-VERSION.tar.gzcd openresty-VERSION/./configuremakesudo make install

The VERSION in the example is replaced with the version number of OpenResty, such as 1.11.2.1. If you need more flexible control over the details during the build process, please read on.

After the installation is successful, we can use openresty to output the html page directly.

②, configuration

First, we can create a working directory:

Mkdir / home/wwwcd / home/www/mkdir logs/ conf/

The logs directory is used to store logs and conf is used to store configuration files.

Next, we create a nginx.conf file under the conf directory with the following code:

Worker_processes 1 error error log logs/error.log;events {worker_connections 1024;} http {server {listen 9000; location / {default_type text/html; content_by_lua 'ngx.say ("

Hello, World!

")';}}

If you are familiar with the configuration of nginx, you should be familiar with the above code. Here we write the html code directly in the configuration file.

③, startup

By default, openresty is installed in the / usr/local/openresty directory with the startup command:

Cd / home/www/usr/local/openresty/nginx/sbin/nginx-p `pwd` /-c conf/nginx.conf

If there is no output, the startup is successful,-p specifies our project directory, and-c specifies the configuration file.

3. Compare with Nginx

Nginx is a high-performance HTTP and reverse proxy service, as well as an IMAP/POP3/SMTP service.

1. Processing response requests quickly

2. Highly concurrent connections

3. Low memory consumption

4. High reliability:

5. High scalability

6. Hot deployment

Nginx has only one master process and a configured number of worker processes. The master process passes the request to worker, and a worker registers an event where blocking may occur (epoll model) and continues to process subsequent requests (non-blocking). When the event is processed, the worker is notified via callback to continue processing the request follow-up (event-driven), and a single worker can handle a large number of requests without easily jamming the entire system.

The separate design of master management process and worker working process makes Nginx have the function of hot deployment, and the executable file of Nginx can be upgraded under the premise of 7 × 24 uninterrupted service. You can also modify configuration files, change log files and other functions without stopping the service.

Openresty is based on nginx to add modules, we are actually talking about the performance of nginx.

4. What problems or pain points have been solved?

OpenResty addresses the pain points of high concurrency, and asynchronous processing increases the overall load capacity of the server, rather than the speed of a request.

At this point, I believe you have a deeper understanding of "what is openResty", might as well come to the actual operation of it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report