In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article is about how to use Nginx+Lua for Web development. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Nginx ("engine x") is a high-performance HTTP and reverse proxy server, as well as an IMAP/POP3/SMTP server. It is known for its stability, rich feature set, sample configuration files, and low consumption of system resources. Lua is written by standard C and can be compiled and run on almost all operating systems and platforms. A complete Lua interpreter is only 200k, and Lua is the fastest of all script engines. The combination of the two can develop high-performance Web applications.
Using Nginx+Lua for Web Development
Openresty combines nginx and lua. 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.
1. Install openresty
Under Ubuntu:
Sudo apt-get install openresty
Under Mac:
Brew install homebrew/nginx/openresty
two。 Configure nginx.conf
Add a server configuration to openresty
Lua_package_path'/ Users/M/workspace/lua/tuyang-lua/?.lua;;'
Server {
Listen 80
Server_name lua.tuyang.dev
Charset utf8
# access_log logs/host.access.log main
Root / Users/M/workspace/lua/tuyang-lua
Location / {
Index index.html index.htm index.php
}
Location ~ ^ / app/ ([- _ 0-9a-zA-Z] +) {
Lua_code_cache off
Default_type 'text/plain'
Content_by_lua_file $document_root/$1.lua
}
}
Lua_package_path sets the search path of lua script, which is equivalent to classPath in Java
Location ~ ^ / app/ all url requests in the / app path will be intercepted and responded to by the location
Lua_code_cache off closes the lua script cache so that during development, after modifying the lua script, you can see the modified results without restarting the server.
Content_by_lua_file finds the lua script that executes
The server root directory defined by $document_root, which is now / Users/M/workspace/lua/tuyang-lua
3. Restart the openresty server
Sudo openresty-s reload
4.helloWorld tutorial
Create a file under the server root directory you just configured and name it index.lua
Ngx.say ('
Hello world!
')
5. Access using a browser
Thank you for reading! This is the end of the article on "how to use Nginx+Lua for Web development". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.