nginx常用配置

1.输出字符串 :ip/test

location /test {
   limit_req zone=one burst=5 nodelay;
   default_type text/html;
   return  200  'cherry';
}

2.图片防盗链

location ~* \.(jpg|png) {
    root html/img;
    valid_referers 192.168.255.11; # 本地ip
    if ( $invalid_referer ) {
        return 403 "此图无法访问";
    }
}

3.ip限制

location / {
    # 同一IP同一时间只允许有一个连接
    # limit_conn addr 1;
    # deny  192.168.1.1; # 禁止访问的ip 或者 ip段
    # allow 192.168.1.0/24;# 允许访问的ip 或者 ip段
}

4.重定向

# shop/goods/3.html => xxx.com/shop/goods?id=3
location /shop {
    rewrite goods/(\d+)\.html$ /tp_shop/goods.php?id=$1 permanent;
}

5.限流

limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s;
server {
   location / {
        limit_req zone=one burst=5 nodelay; # 一秒钟最多访问1个用户,最大访问限度为5
        root   html;
        index  index.html index.htm;
  }
}

6.模拟负载均衡(虚拟机开起三个swoole)

upstream swo_http_up {
  server  192.168.254.130:9501;
  server  192.168.254.130:9502 ;
  server  192.168.254.130:9503;
}
location /swoole {
    proxy_pass http://swo_http_up;
}
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值