Nginx

0.常用互联网架构


1.高可用 

Keepalived(有虚IP)+Nginx


2.正向代理:代理在客户端

   反向代理:代理在服务端

3.架构,Nginx涉及Master进程和Worker进程


4.nginx.conf

虚拟主机配置



二、

devops:开发运维一体化
http{
upstream tl{
  ip_hash;  #配置ip_hash算法
server ip:port weight=2;
server ip:port weight=1; 
}

server{
listen 80;
server_name www.tl.com;

location /{  #/是基于uri,所有请求uri匹配上的走这个
proxy_pass http://t1;
root html; # $host代表域名
  index index.html index.htm;
}

location ~* \.(css|gif|png|jpg|js)$ {
root html;
valid_referers none blocked *.tl.com;
if($invalid_refer){
rewrite ^/ http://www.tl.com/image/403.png;
#return 404;
}
}
}

}
upstream参数
sevice 反向服务地址,加端口
weight 权重
max_fails=1 失败多少次,认为主机已经挂掉
fail_timeout 剔除后重新探测时间
backup 备用服务
max_conns 允许最大连接数
slow_start 当节点关闭,不立即加入(毫秒)
location参数
root #站点根目录
index #首页
proxy_pass #代理服务
proxy_redirect off; #是否允许重定向
proxy_set_header Host $host #

nginx请求过程
server_name:listen/url(请求)--server--location--upstream--web app1...n
location匹配方式
1.location /image  基于路径匹配
2.location ~\.(css|png|js|png|jpeg)$  正则匹配
3.location 基于if条件
root html<---- html是目录,站点根目录
proxy_pass:upstream或url

nginx负载均衡算法
轮询+权重:默认算法
ip_hash:基于hash计算,用于保持session一致性。优先级高于weight
hash(client_ip)%2=index
url_hash:静态资源缓存,节约存储。非官方
hash(url)%node_count=index
least_conn:最少连接数,保证饱和状态
least_time:平均响应时间最快分发给谁











文章参考:https://www.jianshu.com/p/5eab0f83e3b4


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值