Nginx+lua+openresty

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档

文章目录


前言


一、nginx与负载均衡算法

轮询:按照时间分配到不同的服务器

Least Connections:使每台服务器的链接数都尽可能小

IP_HASH:使用户的访问固定在某台服务器上,方便服务器记录session,如果donw了,就到下一个服务器

Generic HASH:可以选择不同的hash模式

Least time:暂时不管

random:随机,也可以设置权重

二、动静分离

请求由nginx到服务器再到数据库就是动态请求;请求图片这些静态资源就是静态请求。

powershell 复制代码
server {
  linsten 9001;
  server_name www.test.com;
  location / {
    				root /data/www;
  }
  location /images {
  					root /data;
  }
}

www.test.com/?后的请求会拼接在/data/www后面,而/images后的请求会拼在/data后面,从而实现动静分离。

三、高可用

主节点宕机后会自动将服务转给从服务。通过keepalived实现请求的转发。

keepalived的conf配置

powershell 复制代码
vrrp_instance VI {
  state master  #主master从backup
  interface enp0s3  #网卡
  virtual_router_id 51  #主从要一致
  priority 100				#优先级
  advert_int 1				#每隔1S发送心跳
  authentication{
  			auth_type PASS   #密码
  			auth_pass 1111
  }

  virtual_ipaddress{   #IP地址
  			10.0.2.39
  	}

四、LUA

五、redis

  • httpredis 功能简单不能set
  • httpredis2moudle 推荐使用
  • lua-openresty-redis 推荐使用

六、防爬虫

1.限制请求头

2.限制ip

3.添加验证码,按顺序点击的可以防

4.限制cookie


总结

nginx和springCloudAlibaba都有限流的功能,区别还是没有很清楚。

相关推荐
刘~浪地球3 小时前
Nginx + Tomcat 整合实战(三):负载均衡与集群部署
nginx·tomcat·负载均衡
灰阳阳13 小时前
Dockerfile实践-构建Nginx镜像
运维·nginx·docker·dockerfile
最好有梦想~1 天前
嵌入式Linux Lua使用ZeroBrane远程调试
linux·嵌入式硬件·lua
ywlovecjy1 天前
macOs安装docker且在docker上部署nginx+php
nginx·macos·docker
tumeng07111 天前
Linux(CentOS)安装 Nginx
linux·nginx·centos
回到原点的码农1 天前
Failed to restart nginx.service Unit nginx.service not found
运维·nginx
siger2 天前
前端部署缓存策略实践
前端·nginx
曲幽2 天前
FastAPI子应用挂载:别再让root_path坑你一夜
python·nginx·fastapi·web·mount·admin·404·docs·root_path
yashuk2 天前
Ubuntu 系统下安装 Nginx
数据库·nginx·ubuntu