网站首页 > 技术教程 正文
1、location匹配先后顺序
说明:
= 表示精确匹配,如果找到,立即停止搜索并立即处理此请求。
~ 表示执行一个正则匹配,区分大小写匹配
~* 表示执行一个正则匹配,不区分大小写匹配
!~ 区分大小写不匹配
!~* 不区分大小写不匹配
^~ 即表示只匹配普通字符(空格)。使用前缀匹配,^表示“非”,即不查询正则表达式。如果匹配成功,则不再匹配其他location
/ 表示通用匹配,任何请求都会匹配到
2、GZIP压缩
gzip on;
gzip_min_length 1k;
gzip_buffers 8 32k;
gzip_comp_level 2; # 指定gzip压缩比,1最小,9最大,压缩比越大越消耗CPU资源
gzip_http_version 1.1; # 压缩版本默认是1.1
gzip_types text/plain text/css application/xml application/x-javascript application/javascript application/json;
3、 URL limit限速
主配置文件nginx.conf:
map $limited $limit {
0 $binary_remote_addr;
1 "";
}
limit_req_zone $limit zone=loginlimit:10m rate=10r/m; #每6秒一个请求,比如:6r/m,每10秒放进来一个请求,按平均算
域名配置location:
location / {
limit_req zone=loginlimit;
proxy_pass http://xxxxxxxx.backend;
}
4、反向代理
upstream xxx_backend {
server 172.168.100.11:8080;
server 172.168.100.12:8080;
}
server {
server_name xxx.example.com;
location / {
proxy_pass http://xxx_backend;
}
}
5、正向代理
upstream xxx_backend {
server 180.101.49.12:80;
}
server {
server_name xxx.example.com;
proxy_connect_timeout 90s;
proxy_read_timeout 100s;
proxy_send_timeout 90s;
location / {
proxy_set_header Host "www.baidu.com";
proxy_pass http://xxx_backend;
}
}
6、静态资源
server {
server_name static.example.com;
root /data/static.example.com/default/; #nginx上静态资源对应存储路径
try_files $uri $uri/ /index.html;
index index.html index.htm index.jsp;
}
猜你喜欢
- 2024-10-10 Nginx web服务器(nginx Web服务器)
- 2024-10-10 Nginx 了解一下?(nginx的理解)
- 2024-10-10 Nginx可以做什么?看完这篇你就懂了
- 2024-10-10 Spring Boot 中的静态资源到底要放在哪里?
- 2024-10-10 「Web开发」Spring MVC 中的静态资源与缓存
- 2024-09-14 Openresty/Nginx 缓存设置(nginx 缓存配置)
- 2024-09-14 Nginx之6大千世界 - (FastCGI)(nginxgui)
- 2024-09-14 一篇文章了解nginx特性,值得收藏
- 2024-09-14 Nginx-location的匹配规则(nginx配置文件中的location)
- 2024-09-14 Nginx主要应用场景|反向代理|负载均衡|动静分离|HTTP服务器
你 发表评论:
欢迎- 08-06linux 和 windows文件格式互相转换
- 08-06谷歌 ChromeOS 已支持 7z、iso、tar 文件格式
- 08-06Linux下比较文件内容的6种方法
- 08-06文件格式及功能汇总
- 08-0610个Linux文件内容查看命令的实用示例
- 08-06Linux-如何区分不同文件类型
- 08-06Zabbix技术分享——监控windows进程资源使用情况
- 08-06Linux系统卡顿?学会ps命令这三招,轻松定位问题进程
- 最近发表
- 标签列表
-
- 下划线是什么 (87)
- 精美网站 (58)
- qq登录界面 (90)
- nginx 命令 (82)
- nginx .http (73)
- nginx lua (70)
- nginx 重定向 (68)
- Nginx超时 (65)
- nginx 监控 (57)
- odbc (59)
- rar密码破解工具 (62)
- annotation (71)
- 红黑树 (57)
- 智力题 (62)
- php空间申请 (61)
- 按键精灵 注册码 (69)
- 软件测试报告 (59)
- ntcreatefile (64)
- 闪动文字 (56)
- guid (66)
- abap (63)
- mpeg 2 (65)
- column (63)
- dreamweaver教程 (57)
- excel行列转换 (56)
本文暂时没有评论,来添加一个吧(●'◡'●)