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

The usage of modules in nginx

2025-02-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article mainly introduces "the usage of modules in nginx". In daily operation, I believe many people have doubts about the usage of modules in nginx. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about the usage of modules in nginx! Next, please follow the editor to study!

1 、

Stub_status module:

Used to show the state of the nginx when processing the connection.

The configuration syntax is as follows:

Syntax:stub_status;Default: Context:server and location are not configured by default

You can edit default.conf with the following configuration:

Vim / etc/nginx/conf.d/default.conf

Then check the correctness of the configuration:

#-t means to check the configuration file;-c means to check the specified configuration file. The default is / etc/nginx/nginx.confnginx-t-c / etc/nginx/nginx.conf

Note here that although default.conf is modified, nginx.conf is always loaded when checking, otherwise an error will be reported:

Because all the .conf files in the conf.d directory are include in nginx.conf.

Then reload the configuration file:

#-s means to send signals to the master process: stop, quit, reopen, reload;-c specify the configuration file directory nginx-s reload-c / etc/nginx/nginx.conf

Active connections: the number of active connections initiated to the backend

Server accepts handled requests: Nginx handled a total of 13 connections, successfully created 13 handshakes (proving that there was no failure in the middle), and handled a total of 7 requests

Reading: the number of Header messages read by Nginx to the client

Writing: the number of Header messages returned by Nginx to the client

Waiting: when keep-alive is enabled, this value is equal to active-(reading + writing), which means that Nginx has been processed and is waiting for the resident connection of the next request instruction.

Therefore, when the access efficiency is high and the request is processed quickly, it is normal to have a large number of Waiting. If there are a large number of reading + writing, the concurrent traffic is very large and is in the process of being processed.

2 、

Random_index module:

Select a random home page in the specified directory.

Configuration syntax:

Syntax:random_index on | off;Default:random_index off; is disabled by default. Context:location is configured under location.

Add random_index on; to the configuration file default.conf and modify the special directory to a custom specified directory.

Put a html page in three colors in the specified directory:

Black.html green.html red.html nginx-test

Then the reload nginx service:

Systemctl reload nginx.service

Use a browser to access pages that display different colors as they are refreshed. It is worth noting that nginx does not load hidden files in the specified directory.

3 、

Sub_module module:

Mainly used for HTTP content replacement.

The syntax is as follows:

1. Syntax:sub_filter old_string new_string; replaces old_string with new_stringDefault: replace old_string with new_string2, Syntax:sub_filter_last_modified on | off;Default:sub_filter_last_modified off;Context:http, server, location without configuration of Context:http, server or location. When client and server interact with each other, nginx verifies whether the server content has changed and is mainly used for caching scenarios. 3. Syntax:sub_filter_once on | configuration under off; Default:sub_filter_once on; Context:http, server and location indicates the default number of matching strings. By default, it is the first match.

Create a submodule.html file in the specified directory:

Nginx-test smallsoup test tomcat test tomcat

Then configure this directory as the root directory in default.conf and configure sub_filter:

It is used to change the tomcat in html to nginx,reload nginx and you can see the page:

However, only the first tomcat has been modified, and the second one has not been modified; if you want to replace them all, you need to configure:

If there is no replacement on the page, it may be caused by the browser cache, which needs to be forced to refresh or refresh after cleaning the cache.

At this point, the study of "the use of modules in nginx" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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

Internet Technology

Wechat

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

12
Report