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 method of restricting access to Module by Nginx limit

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Nginx's limit module is used to restrict access to Nginx.

The limit module consists of two parts:

Limit_conn is used to limit the number of connections limit_req is used to limit the frequency of requests

Limit_conn

The implementation of the limit_conn module is simpler than limit_req. Connections with the same variable value are counted directly, and connections that exceed the limit return a 503 error (Service Temporarily Unavailable).

In fact, because there is usually only one pending request on a connection at some point, and because the keepalive and phase handlers cannot determine the state of the connection (new or old), limit_conn uses the number of requests being processed as the number of connections.

This module contains the following sections:

Limit_conn_zone

This configuration item is used to specify the count space for the number of connections.

# Syntax limit_conn_zone [$variable] zone= [zone-name]: [max-storage-space]; # paragraph http# example limit_conn_zone $binary_remote_addr zone=conn_ip:1m

Limit_conn

This configuration item is used to specify the upper limit of the number of connections.

# Syntax limit_conn [zone-name] [max-connections]; # paragraph http, server, location# sample limit_conn conn_ip 10

Limit_conn_status

Optional. This directive was introduced in version 1.3.15. Specifies the http code (status response code) that is returned when the request is rejected.

# Syntax limit_conn_status [http-code]; # paragraph http, server, location# example limit_conn_status 502

Limit_req

Unlike limit_conn, limit_conn directly specifies the upper limit of the number of connections, while limit_req limits the specified upper limit of the rate (that is, frequency) at which the specified variable occurs through the rate parameter.

This module contains the following sections:

Limit_req_zone

This configuration item is used to specify the count space for the frequency of requests.

# Syntax limit_req_zone [$variable] zone= [zone-name]: [max-storage-space] rate= [max-request-rate]; # paragraph http# example # rate=1r/s indicates a limit of only one request limit_req_zone $binary_remote_addr zone=req_ip:1m rate=1r/s per second

Limit_req

This configuration item is used to call the upper limit of frequency specified by limit_req_zone, as well as optional supplementary parameters.

# Syntax # burst is optional. This is followed by an integer indicating the maximum number of requests allowed to exceed the frequency limit. # nodelay is optional. If you do not want more requests to be delayed, you can use the nodelay parameter limit_req zone=req_ip (burst= [numbers]) (nodelay); # paragraph http, server, location# sample limit_req zone=req_ip burst=5 nodelay

Limit_req_status

Optional. It's the same as limit_conn_status. Specifies the http code (status response code) that is returned when the request is rejected.

# Syntax limit_req_status [http-code]; # paragraph http, server, location# example limit_req_status 502

The above is the whole content of this article, I hope it will be helpful to your study, and I also hope that you will support it.

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