原创

nginx的访问频次控制

温馨提示:
本文最后更新于 2025年06月11日,已超过 366 天没有更新。若文章内的图片失效(无法正常加载),请留言反馈或直接联系我

nginx.conf

 worker_processes  1;
    pid        /mydata/nginx/logs/nginx.pid;
    events {
    worker_connections  1024;
  }
    http {
    limit_req_zone $binary_remote_addr zone=one:10m rate=2r/s;
    include       mime.types;
    default_type  application/octet-stream;
    
    sendfile        on;
    
    keepalive_timeout  65;
    
    #gzip  on;
    upstream admin{
    least_conn;
    
    server  123.207.64.127:80 weight=1 ;
  }
      upstream oneblogadmin{
    least_conn; 
     server  123.207.64.127:38085 weight=1  ; 
     server   1.95.58.220:8085 weight=1 ;
    }
	
	
	server {
    listen       81;
    server_name 123.207.64.127;
       root /mnt/data/;
    # 处理HTTP请求相关配置
   location / {
     limit_req zone=one burst=2 nodelay;
            root   html;
            proxy_pass http://oneblogadmin;
            proxy_connect_timeout 20s;
            proxy_read_timeout  20s;
            proxy_send_timeout 30s; 
            index  index.html index.htm; 
        }
  error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
}

 upstream oneblogweb{
    least_conn; 
     server  123.207.64.127:38443 weight=1  ; 
     server   1.95.58.220:8443  weight=1 ;
    }
	server {
    listen       82;
    server_name 123.207.64.127;
       root /mnt/data/;
    # 处理HTTP请求相关配置
   location / {
     limit_req zone=one burst=2 nodelay;
            root   html;
            proxy_pass http://oneblogweb;
            proxy_connect_timeout 20s;
            proxy_read_timeout  20s;
            proxy_send_timeout 30s; 
            index  index.html index.htm; 
        }
  error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
}



 upstream blog{
    least_conn; 
     server  123.207.64.127:38080 weight=1  ; 
     server   1.95.58.220:8080  weight=1 ;
     server   1.95.58.220:8081  weight=1 ;
    }
	server {
    listen       83;
    server_name 123.207.64.127;
       root /mnt/data/;
    # 处理HTTP请求相关配置
   location / {
     limit_req zone=one burst=2 nodelay;
            root   html;
            proxy_pass http://blog;
            proxy_connect_timeout 20s;
            proxy_read_timeout  20s;
            proxy_send_timeout 30s; 
            index  index.html index.htm; 
        }
  error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
}



    server {
   limit_req zone=one burst=2 nodelay;
    listen       80;
    server_name 123.207.64.127;
    root  /mnt/data;
        location /images { 
            root /mnt/data/;
        } 
           location /oneblog {
            #路径配置
            #location 匹配规则最好不要与访问路径相同,否则会追加在路径后面,当作访问地址
            #root 与 alias root是真实的路径,而alias的最后一层会被 location 访问规则代替
            #所指定的路径注意访问权限&注意nginx运行时使用的身份
            root /mnt/data/;
        } 	
    location / {
    root   /mnt/data;
    index  index.html index.htm;
  }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
    root   html;
  }
  }
    
    server {
    listen 80;
    server_name localhost;
    root  /mnt/data;
    error_page 403 /error.html;
    location = /error.html {
    return 404;
  }
    autoindex off;
    autoindex_exact_size off;
    autoindex_localtime off;
    
    location ^~ / {
    proxy_set_header Host :;
  }
    
    location ~*\.(jpg|gif|png|swf|flv|wma|wmv|asf|mp3|mmf|zip|rar|js|css)$ {
    expires 30d;
  
  }
  }
  
  
  
  
  }
    
正文到此结束