In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
Most people do not understand the knowledge points of this "nginScript case Analysis of nginx" article, so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "nginScript case Analysis of nginx" article.
Let's talk about nginx first.
Nginx [engine x] is the most popular and excellent web server and reverse proxy server in the world. According to the statistics of third-party companies, at least 23% of the servers in the world use nginx, and of course this number is still expanding. At present, it is also the first choice of domestic bat, so this is why we pay attention to it in the first place.
Nginx can mainly do the following:
1. Working in the seventh layer of tcp, all the contents of http protocol can be analyzed and processed.
2. Support lua,perl,javascript dynamic language
3. Support third-party plug-ins
Let's talk about nginscript.
1. Nginscript is a subset of javascript/ecmascript. It implements most of the capabilities of the javascript language, does not fully comply with the ecmascript standard, and abandons the more difficult parts of javascript.
2. Nginscript is not implemented through the V8 engine. Instead, it is achieved through a small virtual machine (vm) that is smaller, consumes less energy, and is more in line with the nginx application scenario. It can be understood that nginx has implemented a set of lexical parsing for it.
3. Nginscript runs in the configuration file of nginx. For example: in the nginx.conf file. So nginscript can do everything that traditional configuration files can handle, while making configuration management dynamic. This is the most important reason for the emergence of nginscript.
4. Nginscript exists as a nginx plug-in. The plug-in is called njs. Like other nginx plug-ins, we need to recompile nginx to complete the installation.
5. Nginscript is currently in the early state of research and development. You can communicate with nginx team and put forward your request by email and other means.
How to install nginscript
Just follow the steps given by the authorities:
/ / 1. Download the latest nginx package, which can be found in wget / / 2, decompress tar-xzvf nginx-1.9.4.tar.gz / / 3, and obtain the nginscript module through mercurial. If mercurial is not installed here, you need to run yum install mercurial hg clone first.
/ / 4. Compile nginx. Only the njs module is specified here. Remember to install other required modules together. If you have not compiled nginx and some dependent modules need to be installed by yum, please search for them yourself. Cd nginx-1.9.4. / configure-- add-module=../njs/nginx-- prefix=/usr/local make make install ok, this is all installed, and we can start playing.
How to use nginscript
The use of nginscript is mainly due to the addition of two instructions to the configuration system of nginx. The specific instructions are as follows:
Js_set, set the value of the variable in the configuration
Js_run, direct execution of configuration rules
1. Take a look at how js_set works in nginx.conf.
Http {js_set $msg "var str = 'hello,imweb'; / / javascript str;"; server {... Location / {return 200$ msg;}
Results:
In the above example, you can see that we can arbitrarily set the value of a variable to nginx through js. These variables can be used everywhere in the nginx configuration. For example: proxy_pass,limit_req_zone, and sub_filter. This has greatly improved the flexibility compared to the previous configuration.
2. Running rules and scenarios of js_run
Js_run is run in the location instruction. Matching the path of the specified location will execute the corresponding javascript.
Js_run generates the content returned by http directly through javascript.
Here is a specific example:
Location / imwebteam {js_run "var res; res = $r.response; res.status = 200; res.send ('HelloJournal imwebmasters'); res.finish ();";}
This result is the same as the first one. I won't repeat it here.
3. In addition to processing two instructions, there is an important variable $r
You can have complete control over http request requests through js_set and js_run, which is controlled by the use of the variable $r. What in $r can be seen through the following simple example.
Http {js_set $summary "var a, s, h; s ='js summary\ n\ nregions; s + = 'method:' + $r.method +'\ nregions; s + = 'httpversion:' + $r.httpversion +'\ nregions; s + = 'host:' + $r.headers.host +'\ nregions; s + = 'remoteaddress:' + $r.remoteaddress +'\ nregions; s + = 'uri:' + $r.uri +'\ nregions; s + = 'headers:\ n' For (h in $r.headers) {s + = 'header\ "+ h +'\" is\ "'+ $r.headers [h] +'\"\ nregions;} s + = 'args:\ ncustomers; for (an in $r.args) {s + =' arg\ "+ a +'\" is\ "+ $r.args [a] +'\"\ ncustomers;} s; "; server {listen 8000; location / imwebteam {return 200$ summary;}
The result is shown in the figure:
The problems existing in nginscript at present
After the above introduction, I believe you have a basic understanding of nginscript. So let's see what's wrong with this newborn.
First of all, the debugging method is weak. At present, it is still relatively primitive, displayed in the way of log, and the level of detail of the error log is not satisfactory.
Secondly, the control is weak. At present, the processing strength of nginscript is limited to the processing of http request and the return of response, and it is still unable to dynamically deal with some contents other than nginx requests, such as dynamic user data or dynamic update of forwarding configuration table.
Finally, the overall realization is weak. The overall structure is still relatively simple, the running environment of js_run and js_set is not quite the same, and the code snippet in which js_set executes ok will have some exceptions on js_run.
Generally speaking, nginscript is still a newborn with bright wishes and prospects. It takes some time to polish and optimize. I also hope that you can provide a lot of comments and feedback, or even submit your own plug-ins. So that it can grow better.
The above is about the content of this article "nginScript case Analysis of nginx". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.
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.