限制cache访问次数php,配置nginx限制ip访问次数

本文详细介绍了如何修改Nginx配置文件以实现限流和缓存策略,并设置了一个包含两台服务器的上游集群进行负载均衡。配置包括limit_req_zone用于限制请求速率,proxy_cache_path设置缓存路径和参数,以及通过proxy_cache和proxy_cache_key启用缓存。此外,还展示了平滑重启Nginx的方法。
摘要由CSDN通过智能技术生成

修改服务器上的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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值