文章

配置nginx限制ip访问次数

修改服务器上的nginx的配置文件

/usr/local/nginx/conf/nginx.conf

http {
limit_req_zone $binary_remote_addr zone=one:10m rate=3000r/m;
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=one:8m max_size=3000m inactive=600m;
proxy_temp_path /var/tmp;

include mime.types;
default_type application/octet-stream;

gzip on;
gzip_comp_level 6;
gzip_vary on;
gzip_min_length 1000;
gzip_proxied any;
gzip_types text/plain text/html text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
gzip_buffers 16 8k;

#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;

upstream wedate{
server 10.0.0.48:8080;
server 10.0.0.50:8080;
}

server {
listen 8080;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;

location / {
limit_req zone=wedate_zone burst=30;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_set_header Connection "";
proxy_http_version 1.1;
proxy_cache one;
proxy_cache_key sfs$request_uri$scheme;
proxy_pass http://wedate;
}

nginx平滑重启

nginx -t -c /usr/local/nginx/conf/nginx.conf

1 0

发表评论