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

How to use the module to monitor nignx

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article mainly introduces the method of using the module to monitor nignx, and also introduces the common commands of nginx, the method of opening directory list by nginx and the access control of nginx. I believe you have a certain understanding of nginx after reading the complete article.

1.nginx common commands

Nginx-v # View version

Nginx-V # View compilation options

Nginx-t # checks the configuration file syntax. Add-c to specify the configuration file.

Nginx-s reload # reloads the configuration file without restarting

two。 Open directory list

Add the following code to the http {} section

When autoindex on;# is enabled, the display directory autoindex_exact_size off;# defaults to on, showing the exact size of the file, all in bytes. When changed to off, the approximate size of the file may be shown. The unit may be converted to kB or MB or GB. It is recommended to turn off autoindex_localtime on;# by default to off, and the file time displayed is GMT (world world) time. When changed to on, the file time displayed is the file server time. It is recommended to turn it on.

3. Monitoring nginx

Monitoring nginx needs the module "--with-http_stub_status_module".

Nginx-V & > 123.txtdowcat 123.txt | grep status # use this command to check whether this module is loaded

On, add a "location" in the server section

Location / status {

Stub_status; #

Access_log off

}

Parameter description

Active connections-number of active connections server accepts handled requests-handled a total of 107520387 connections, successfully created 107497834 handshakes, handled a total of 639121056 requests each connection has three states waiting, reading, writing reading-read the number of Header messages from the client. This operation only reads the header information, and immediately enters the writing state after reading, so the time is very short. Writing-the number of Header messages from the response data to the client. This operation not only reads the header, but also waits for the service response, so it takes a long time. Waiting-A resident connection that waits for the next request instruction after keep-alive is enabled. Normally, the number of waiting is relatively large, which does not indicate poor performance. On the contrary, if the number of reading+writing is large, it means that there is a problem with service concurrency.

Test long and short connections

Configure "keepalive_timeout" to 0 (change to short connection) to restart and refresh the status page

# as you can see from the image above, a tcp connection is established for each request

Refresh the status page after changing the "keepalive_timeout" configuration to 10 restart

# continuous refresh shows that the number of requests keeps increasing, but the number of tcp connections will not increase until 10 seconds later.

Why to use long connection? where is long connection better than short connection?

A long connection is actually a reuse of TCP connections. There are generally dozens of resources in a web page. If a short connection is used, dozens of tcp requests will be disconnected to request a short link to a web page, which consumes a lot of resources.

But using a persistent connection is different. Dozens of requests are connected with the same tcp, but it cannot be connected permanently. This will fill the port of the server, so there is a timeout period beyond which you can disconnect without a new request.

4. access control

Scope of application, which can take effect in http server location section.

Ip control

Location / status {allow 192.168.0. Swap 24; deny all;}

# the above indicates that the resource "/ status" can only be accessed by the network segment of 192.168.0.0Uniple 24. The matching rules match from top to bottom like acl, and the match is not matched after the first item.

Password control location / status {auth_basic Please enter your account password; # prompt message, some browsers may not display the path where the auth_basic_user_file / etc/nginx/passwd; # account password is stored}

# indicates that "/ status" is required to access this url. Enter the password.

Password file generation

Yum install httpd-tools.x86_64-y # install http tool, this software is required to generate password file

Htpasswd-bc / etc/nginx/passwd cs1 12345password-c is to generate a password file, add two accounts, and add a second without-c.

# generate a "passwd" file in the "/ etc/nginx/" path and store it in an account with cs1 password 123456

After reading the above, do you have any further understanding of nignx? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel. Thank you for reading.

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

Servers

Wechat

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

12
Report