开源众包
164人浏览/24人投稿
1021天前
已托管赏金
查看文档是通过#會話狀態儲存在了10m的名稱為"one"這個區域。該區域平均查詢限制在每秒1個請求limit_req_zone $binary_remote_addr zone=mylimit:10m rate=10r/s;#每秒平均請求不超過1個請求 突發不超過5個查詢 如果不需要限制突發延遲內的超額請求,則應使用nodelaylimit_req zone=mylimit burst= 5 nodelay;以上两个限制。以下是conf文件。server {listen 443 ssl http2;listen [::]:443 ssl http2;server_name api.mail.com;#會話狀態儲存在了10m的名稱為"one"這個區域。該區域平均查詢限制在每秒1個請求limit_req_zone $binary_remote_addr zone=mylimit:10m rate=10r/s;#每秒平均請求不超過1個請求 突發不超過5個查詢 如果不需要限制突發延遲內的超額請求,則應使用nodelaylimit_req zone=mylimit burst= 5 nodelay;#限制单个IP同时最多能持有10个连接。limit_conn perip 10;root /home/wwwroot/api.mail.com;ssl_certificate /usr/local/nginx/conf/ssl/mail.com/fullchain.cer;ssl_certificate_key /usr/local/nginx/conf/ssl/mail.com/mail.com.key;ssl_protocols TLSv1.2 TLSv1.3;ssl_ciphers TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256:EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;ssl_prefer_server_ciphers on;ssl_session_timeout 10m;ssl_session_cache builtin:1000 shared:SSL:10m;ssl_buffer_size 1400;add_header Strict-Transport-Security max-age=15768000;ssl_stapling on;ssl_stapling_verify on;#ssl_dhparam /usr/local/nginx/conf/ssl/dhparam.pem;#error_page 404 /404.html;#error_page 502 /502.html;error_page 404 /404.html;proxy_intercept_errors on;location /api/ {limit_req zone=mylimit;proxy_pass http://127.0.0.1:9000/api/ ;proxy_http_version 1.1;proxy_cache_bypass $http_upgrade;proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection "upgrade";proxy_set_header Host $host;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 X-Forwarded-Host $host;proxy_set_header X-Forwarded-Port $server_port;}location =/robots.txt {default_type text/html;add_header Content-Type "text/plain; charset=UTF-8";return 200 "User-Agent: *\nDisallow: /";}access_log off;}nginx -t 出现错误nginx: [emerg] "limit_req_zone" directive is not allowed here in /usr/local/nginx/conf/vhost/api.mail.com.conf:18解决问题,先到先得。直接在此处提交方案。