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

22pi Nginx common function module

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

1 common modules of MagneNginx (log slicing)

1) We can define the logs of different websites in the virtual host configuration and put them in the log files named after ourselves.

2) systemctl reload nginx

Cd / var/log/nginx & & ll

4) cut the log and let it be named according to the date of each day.

5recording logrotate-f / etc/logrotate.d/nginx cutting

2. View the Nginx status module

1) cd / etc/nginx/conf.d

2) systemctl restart nginx

3) curl www.oldzhang.com

Number of requests:http requests

Handled: number of successful connections

Accepts: total number of connections

3, catalog index module

Catalog indexing scenarios like this:

Charset utf-8,gbk

Default Chinese directory garbled, add to solve garbled

Autoindex on | off

Default: autoindex off

Context: http, server, location

Autoindex_localtime on

The default is off, and the file time displayed is GMT time.

Common parameters of autoindex

Autoindex_exact_size off

The default is on, which shows the exact size of the file, in bytes.

Change to off to show the approximate size of the file, in kB or MB or GB.

4Det Nginx access control module

5Die Nginx web page access login module

1) install the httpd password tool

Yum install httpd-tools-y

2) generate password configuration file

Htpasswd-b-c / etc/nginx/auth_conf oldzhang oldzhang

Create a new password file,-c create a new file-b allow the command line to enter a password

3) modify the configuration file

6. Request limit (http request)

There is another kind of connection restriction (tcp connection). The disadvantage of this restriction is that as long as one tcp connection request is successful, there can be numerous http requests, so the tcp connection is not meaningful now.

1) define request limit domain

Http {limit_req_zone $binary_remote_addr zone=www_zone:10m rate=1r/s;}

Zone=www_zone domain name

10m capacity 10m

Maximum number of requests per second for rate=1r/s operation

2) reference restriction domain

Server {limit_req zone=www_zone burst=3 nodelay;}

Zone=www_zone domain name

Maximum number of delays in burst operation

Nodelay does not have this character. All requests are stuck in queue.

3) Test

Ab-n 20-c 1 http://www.oldzhang.com/ simulates 20 concurrency and runs a maximum of 1 in 1 second

Grep "2019-08-24" error.log | wc-l can be seen in the error log. One request is allowed, 3 delays are waiting, and 16 are restricted.

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