From the view of the voting results of Nginx configuration and application detailed topic, Nginx is now the only Web server after Apache and Ms IIS. Nginx's excellent high concurrency support and efficient load balancing are the reasons why we choose it. But sometimes we want it to do more. This article will show you how to speed up the IP and directory under Nginx, which is a common requirement in some application scenarios.
Nginx can be httplimitzonemodule and httpcoremodule two directories to speed limit.
Example:
Limit_zone one $binary _remote_addr 10m; Location/{Limit_conn one 1; Limit_rate 100k; }
Description
Limit_zone is a container that stores the session state for each IP. This example defines a 10m container that can handle 320,000 sessions according to 32bytes/session.
Then set it for the directory.
Limit_conn one 1;
is to restrict the initiation of only one connection per IP.
Limit_rate 100k;
is a speed limit of 100k per connection. Note that this is the speed limit for the connection, not the IP speed limit. If an IP allows two concurrent connections, then this IP is the speed limit limit_rate x 2.
Nginx Monitoring
in the above configuration, we first define a location ~ ^/nginxstatus/,
This allows the http://localhost/NginxStatus/to monitor the operation information of Nginx, and displays the following contents:
Active CONNECTIONS:70 Server accepts handled requests 14553819 14553819 19239266 reading:0 writing:3 waiting:67
the contents of the Nginxstatus display are as follows:
Active connections– The number of active connections currently being processed by Nginx.
Server accepts handled requests-a total of 14,553,819 connections were processed, 14,553,819 handshakes were successfully created (proving that there was no failure in the middle), and a total of 19,239,266 requests were processed (average Each handshake handles 1.3 data requests).
Reading--The number of Header information that Nginx reads to the client.
Writing--The number of Header information returned to the client by Nginx.
Waiting--when keep-alive is turned on, this value is equal to active-(reading + writing), meaning that Nginx has processed the host connection that is waiting for the next request instruction.
Nginx anti-theft chain
Location ~* \. (gif|jpg|png|swf|flv) $ {root Htmlvalid_referers none blocked *.nginxcn.com;if ($invalid _referer) {rewrite ^/ Www.nginx.cn#return 404;}}
For IP and directory speed limits under Nginx