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; }