nginx的日志

```
#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;
remote_addr 访问ip地址
remote_user 访问的用户
time_local 本地时间
request 包括请求方式 请求地址 请求协议版本
status 状态码
body_bytes_sent 发送的大小
http_user_agent 用户的请求头
http_x_forwarded_for
```

禁止访问

```
可以写在server或者location里面
deny 192.168.21.1;
allow 192.168.21.131;
deny 192.168.21.0/24; ```

反向代理

- 起到保护网站安全的作用
- 可以缓存静态文件
- 实现负载均衡 F5 A10 lvs haproxy nginx

```
upstream django {
server 192.168.21.128:81;
}
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _; # Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf; location / {
proxy_pass http://django;
} ```

权重

weight

```
upstream django {
server 192.168.21.128:81 weight=3;
server 192.168.21.131:81
}
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _; # Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf; location / {
proxy_pass http://django;
}
}
得到的结果是:
访问128的3次,才访问131的一次
```

ip_hash

每个请求的ip做hash运算,这样每个固定的访客都会被负载到后端固定的机器

```
upstream django {
ip_hash;
server 192.168.21.128:81
server 192.168.21.131:81
}
```

backup

当前面的都访问不到,则请求backup的备份,只要有一个通,则不会走backup

```
upstream django {
server 192.168.21.128:81;
server 192.168.21.131:81;
server 192.168.21.131:82 backup;
}
```

nginx location匹配规则

```
location = / {
精确匹配/ ,后面不能带其他的东西
[ configuration A ]
} location / {
所有的以/开头的地址
[ configuration B ]
} location /documents/ {
只匹配/documents/
[ configuration C ]
} location ^~ /images/ {
# 匹配以/images/开头。
~严格大小写
[ configuration D ]
} location ~* \.(gif|jpg|jpeg)$ {
以(gif|jpg|jpeg)结尾的文件
~* 不区分大小写
[ configuration E ]
}
优先级
= > 完整路径 > ^~ > /
```

location分离

```
server { listen 80 ;
server_name www.taobao.com taobao.com;
location / {
proxy_pass http://192.168.21.131:82;
}
location ~*\.(jpg|gif|png)$ {
root /data/img;
}
```

status

```
location /status {
stub_status on;
}
```

压缩

```
gzip on
提高响应速度,节省带宽
```

Nginx负载均衡、location匹配的更多相关文章

  1. 浅谈Nginx负载均衡原理与实现

    1.Nginx能做什么? Nginx可以两件事: -- HTTP请求  经过官方测试Nginx可以承受5万的并发量.可用来做静态资源的图片服务器 --负载均衡,如下解释什么是负载均衡. 2.负载均衡 ...

  2. nginx负载均衡简单配置

    nginx负载均衡简单配置准备三台虚拟机来做这个实验:192.168.232.132        web服务器192.168.232.133        web服务器192.168.232.134 ...

  3. LVS+nginx负载均衡知识点1

    lvs+nginx负载均衡 1       学习目标 掌握什么是负载均衡及负载均衡的作用和意义. 了解lvs负载均衡的三种模式. 了解lvs-DR负载均衡部署方法. 掌握nginx实现负载均衡的方法. ...

  4. Nginx系列一:正向代理和反向代理、Nginx工作原理、Nginx常用命令和升级、搭建Nginx负载均衡

    转自https://www.cnblogs.com/leeSmall/p/9351343.html 仅供个人学习 一.什么是正向代理.什么是反向代理 1. 正向代理,意思是一个位于客户端和原始服务器( ...

  5. Nginx记录-nginx 负载均衡5种配置方式(转载)

    nginx 负载均衡5种配置方式 1.轮询(默认)   每个请求按时间顺序逐一分配到不同的后端服务器,如果后端服务器down掉,能自动剔除.  2.weight 指定轮询几率,weight和访问比率成 ...

  6. lvs+nginx负载均衡

    1       学习目标 掌握什么是负载均衡及负载均衡的作用和意义. 了解lvs负载均衡的三种模式. 了解lvs-DR负载均衡部署方法. 掌握nginx实现负载均衡的方法. 掌握lvs+nginx负载 ...

  7. nginx负载均衡(5种方式)、rewrite重写规则及多server反代配置梳理

    Nginx除了可以用作web服务器外,他还可以用来做高性能的反向代理服务器,它能提供稳定高效的负载均衡解决方案.nginx可以用轮询.IP哈希.URL哈希等方式调度后端服务器,同时也能提供健康检查功能 ...

  8. nginx 负载均衡5种配置方式

    nginx 负载均衡5种配置方式 1.轮询(默认) 每个请求按时间顺序逐一分配到不同的后端服务器,如果后端服务器down掉,能自动剔除. 2.weight 指定轮询几率,weight和访问比率成正比, ...

  9. nginx负载均衡实验

    Nginx负载均衡概述 Web服务器,直接面向用户,往往要承载大量并发请求,单台服务器难以负荷,我使用多台WEB服务器组成集群,前端使用Nginx负载均衡,将请求分散的打到我们的后端服务器集群中,实现 ...

  10. nginx负载均衡、nginx ssl原理及生成密钥对、nginx配制ssl

    1.nginx负载均衡 新建一个文件:vim /usr/local/nginx/conf/vhost/load.conf写入: upstream abc_com{ip_hash;server 61.1 ...

随机推荐

  1. Spring Cloud 和 Dubbo 哪个会被淘汰?

    今天在知乎上看到了这样一个问题:Spring Cloud 和 Dubbo哪个会被淘汰?看了几个回答,都觉得不在点子上,所以要么就干脆写篇小文瞎逼叨一下. 简单说说个人观点 我认为这两个框架大概率会长期 ...

  2. vi / vim 键盘图(清晰打印版,桌面背景好图)

    PDF File https://files.cnblogs.com/files/RioTian/vivim-graphical.zip?t=1704439837&download=true ...

  3. Windows Tools | How To Install VS Microsoft C++ Build Tools on Windows

    This can be used for installing anything that requires C++ compiler on Windows. Installation steps D ...

  4. 2019年第十届蓝桥杯国赛C++A组

    蓝桥杯历年国赛真题汇总:Here 最后编辑时间: 2021年5月27日 统一声明 如果不写默认带有常用头文件 如果不表明主函数默认表示在 void solve(){} 默认使用 using names ...

  5. P4913【橙】

    蕾姆了,上一道题做的好烦,结果直接把上一题的代码稍微改改就直接五分钟做出了另一道题,就是这道橙题.虽然只是一道橙题,但上一题代码得以复用显得自己没浪费那么多时间,显得自己还是有不少收获的.心里平摊多了 ...

  6. WIN32 动态 UAC 提权

    UAC(User Account Control) 是 Windows 平台的用户权限控制.它可以让程序使用管理员权限执行某些操作. 静态 UAC 提权 静态 UAC 提权让程序一直运行在管理员权限下 ...

  7. Postman调试grpc

    转载请注明出处: 1.检查自己的postman是否支持 grpc,通过 File -> new -> ,出现如下图,则表示支持: 2.点击上图的grpc就会自动创建一个 grpc 的req ...

  8. Scan Synthesis Practice

    不同上升沿触发器如何进行scan chain DFT实例 Synopsys 工具文档 Mentor DFT脚本 add_clocks 0 clk - 0表示上升沿 Synopsys DFT脚本 更改n ...

  9. Keep English Level-01

    state -- 声称,宣称,国家,政府 state-owned -- 国有的 He stated that "hell will break loose,politically and m ...

  10. [转帖]聊聊TPS、QPS、CPS概念和区别

    https://cloud.tencent.com/developer/article/1859053 TPS 概念 TPS:是TransactionsPerSecond的缩写,也就是事务数/秒.它是 ...