首页
归档
朋友
关于我
留言
【Wiki知识库】
Search
1
虚拟机无法ping不通百度,并无法访问浏览器
4,586 阅读
2
mysql使用or条件使索引失效
3,618 阅读
3
mysql如何在一对多查询时选取时间最近的一条记录
2,972 阅读
4
根据MySQL获取当天,昨天,本周,本月,上周,上月,本月的起始时间
2,433 阅读
5
git常用命令大全
1,600 阅读
PHP
面向对象
设计模式
知识汇总
常用函数
PHP框架知识
数据库
MySQL
服务器
Docker
虚拟机
Nginx
缓存相关
Redis
前端
中间件
RabbitMQ
网络编程
HTTP相关
Swoole
Workerman
工具软件
Git
Typecho
杂乱无章
面试指南
PHP相关
MySQL面试汇总
中间件相关
开发技巧 | 优化
Search
标签搜索
php
mysql
代码片段
linux
Thinkphp
Redis
nginx
mysql优化
docker
面试指南
面向对象
git
Laravel框架
http协议
RabbitMQ
Redis性能优化
设计模式
linux命令
编译安装
PhpSpreadsheet
黎明强
累计撰写
70
篇文章
累计收到
58
条评论
首页
栏目
PHP
面向对象
设计模式
知识汇总
常用函数
PHP框架知识
数据库
MySQL
服务器
Docker
虚拟机
Nginx
缓存相关
Redis
前端
中间件
RabbitMQ
网络编程
HTTP相关
Swoole
Workerman
工具软件
Git
Typecho
杂乱无章
面试指南
PHP相关
MySQL面试汇总
中间件相关
开发技巧 | 优化
页面
归档
朋友
关于我
留言
搜索到
4
篇与
nginx
的结果
2021-03-17
Nginx缓存相关指令以及配置示例
相关指令proxy_cache开启缓存(对上游服务器数据)指定某一个zone名称)语法 : proxy_cache zone | off; 默认值 : proxy_cache off; 上下文 :httpproxy_caceh_path缓存的路径,path : 缓存目录路径keys_zone : 1M可以缓存8千多个key语法 : proxy_cache_path path [levels=levels][use_temp_path=on|off] keys_zone=name:size [inactive=time] [max_size=size] [min_free=size] [manager_files=number] [manager_sleep=time] [manager_threshold=time] [loader_files=number] [loader_sleep=time] [loader_threshold=time] [purger=on|off] [purger_files=number] [purger_sleep=time] [purger_threshold=time]; 默认值 : proxy_cache_path off; 上下文 : http可选参数可选参数含义path缓存文件的存放路径 【必选】levelpath的目录层级use_temp_pathoff直接使用path路径,on使用proxy_temp_path路径keys_zonename是共享内存名称;size是共享内存大小 【必选】inactive在指定时间内没有被访问缓存会被清理;默认10分钟max_size设定最大的缓存文件大小,超过将由CM清理manager_filesCM清理一次缓存文件,最大清理文件数;默认100manager_sleepCM清理一次后进程的休眠时间,默认200毫秒manager_thresholdCM清理一次最长耗时;默认50毫秒loader_filesCL载入文件到共享内存,每批最多文件数;默认100loader_sleepCL加载缓存文件到内存中,进程休眠时间;默认200毫秒loader_thresholdCL每次载入文件到共享内存的最大耗时,默认50毫秒proxy_cache_key缓存key信息语法: proxy_cache_key string; 默认值 : proxy_cache_key $scheme$proxy_host$request_uri; 上下文 : http、server 、 locationproxy_cache_valid语法: proxy_cache_valid [code..] time; 默认值: - 上下文:http、server 、 location 配置示例:proxy_cache_valid 60m; // 只对200/301/302的响应码缓存upstream_caceh_status变量变量名: upstream_cache_statusMISS : 未命中缓存HIT : 命中缓存EXPIRED : 缓存过期STALE : 命中了陈旧缓存REVALIDDATED : Nginx验证陈旧缓存依然有效UPDATING : 内容陈旧,但正在更新BYPASS : 响应从原始服务器获取配置示例虚拟机做演示作为上游服务器 192.168.253.131作为代理服务器 :192.168.253.130代码演示上游服务器配置用9001、9002这2个端口做为2台服务器。并且把对应的端口号开启,然后创建9001/9002目录。server { listen 9001; root /opt/html/9001; location / { index index.html index.htm; } } server { listen 9002; root /opt/html/9002; location / { index index.html index.htm; } } 代理服务器配置配置虚拟渔民Host /ect/host#缓存配置 proxy_cache_path /opt/nginx/cache_temp levels=2:2 keys_zone=cache_zone:30m max_size=32g inactive=60m use_temp_path=off; #反向代理IP upstream cache_server { server 192.168.253.131:9001; server 192.168.253.131:9002; } server { listen 80; server_name cache.lmq-nginx.com; location / { proxy_pass http://cache_server; #开启缓存 proxy_cache cache_zone; proxy_cache_valid 200 5m; #缓存有效5分钟 add_header Nginx-Cache-Status "$upstream_cache_status";#查看缓存状态变量 } } 重载nginx,并运行运行访问开启缓存访问,一直访问9001 ,并且会生成缓存文件,这里定义到/opt/nginx/temp_path其他说明1. 怎么修改缓存的key呢location / { proxy_pass http://cache_server; #开启缓存 proxy_cache cache_zone; proxy_cache_valid 200 5m;#缓存有效期5分钟 add_header Nginx-Cache-Status "$upstream_cache_status";#查看缓存状态变量 #改变key名 proxy_cache_key $proxy_host$reuqest_uri; #主机名+文件名 }2. 设置上游服务器的缓存有效期虽然代理服务器设置了有效期5分钟,但是可以由上游服务器去控制在上游服务器设置server { add_header X-Accel-Expires 5; //5秒有效 locatoin / { .... } }
2021年03月17日
488 阅读
0 评论
0 点赞
2021-01-28
nginx中的rewrite指令
rewrite功能根据指定正则表达式匹配规则,重写URL语法结构语法 : rewrite regex replacement [flag] 默认值 : - 上下文 ; server 、 location 、 if 示例 rewrite /images/(.*\.jpg)$ /pic/$1; //将/images下的*.jpg图片重写到/pic目录下的图片这个$1 可以理解为 www.xxx.com/images/1.jpg 把这个1.jpg 参数传递到pic/目录下 ,查看pic/下是否有1.jpgrewrite中的flagflag可选值以及含义这里重点看last、break的可选值。场景示例场景1server { location /search { rewrite ^/(.*) http://www.baidu.com redirect; //访问xxx.com/search 任意字符 会临时重定向到百度上。 } }场景2流程顺序比较复杂,多看看。访问xxx.com/images 重写到/pic下,/pic下又重写到/photos下。写入测试数据cd '网站目录' mkdir imgages mkdir pic mkdir photos echo "我在images目录下" > images/index.html echo "我在pic目录下" > pic/index.html echo "我在photos目录下" > photos/index.htmlserver { location /images { rewrite /images/(.*)$ /pic/$1; } location /pic { rewrite /pic/(.*) /photos/$1 } location /photos { } }想想最后是会访问到那个?答: 最后是会访问到photos下。一层一层匹配到最后的photos目录下。(再次说明 这个$1 就是一个参数变量,访问xxx.com/images/index.html),实际上这个index.html 就是变量。最后重写到/photos/index.html ,场景3还是拿上述举例。如果在/pic的location段后,增加break 的flag。会重定向哪里?server { location /images { rewrite /images/(.*)$ /pic/$1 break; //增加break的flag,终止需要匹配规则 } location /pic { rewrite /pic/(.*) /photos/$1; } location /photos { } }访问xxx.com/images 匹配到/pic,并且终止循环匹配去找。而直接去找pic下的文件,如果有就返回。就中止继续找了。场景4还是拿场景2举例。如果在/pic的location段后,增加last 的flag。会重定向哪里?server { location /images { rewrite /images/(.*)$ /pic/$1 last; //增加last的flag,重新在server段找 } location /pic { rewrite /pic/(.*) /photos/$1; } location /photos { } }访问xxx.com/images,匹配到pic,加了last会在server段找是否有location /pic的内容,有就匹配。匹配到了/pic 又重写到photos,最后还是访问photos目录下。
2021年01月28日
706 阅读
0 评论
0 点赞
2021-01-28
nginx中return和rewrite指令同时存在,先执行顺序哪个?
前文如果return指令跟rewrite指令同时存在先执行哪个呢?场景示例模拟数据server { location /images { rewrite /images/(.*)$ /pic/$1 last; return 200 "return 200 in /images"; } location /pic { rewrite /pic/(.*) /photos/$1; return 200 "return 200 in /pic"; } location /photos { return 200 "return 200 in /photos"; } }分别在/images、/pic、/photos的location段增加return 返回200状态码并输出字符串流程访问xxx.com/images/index.html ,会进入/images的location段中,在/images中,进行rewrite指令,将images/index.html重写到/pic/的index.html,并且有last 值。遇到last值,会重新触发请求。在server段找/pic的location段。匹配到location的/pic后 ,又重写,将/pic的index.html重定向到/photos目录下的index.html。(注意/pic段没有加last值,意味着流程顺序执行!)没有加flag标签。所以/pic段中依然执行下面的命令,会走retrun 200 "return 200 in /pic" 之后就中断。场景2如果在/pic段中增加flag的break,会执行什么?当遇到break,会重写找/photos段,不会执行return 200 in /pic,注意事项如果当你直接访问xxx.com/photos/index.html, 但是又有return指令, 会优先执行return指令 , 并不会返回photos/index.html的页面,直接返回return结果给你。如果没有return指令才会找目录对应下的有没有index.html文件。
2021年01月28日
739 阅读
0 评论
0 点赞
2020-12-24
Nginx编译安装
Nginx编译安装配置参数nginx是支持模块化设计的,可以选择性将某些模块编译进nginx中,也可以去除掉某些模块不编译进来。下面是编译安装的常见参数:参数含义--prefix指定安装的目录--user运行nginx的worker子进程的属主(用户)--group运行nginx的worker子进程的属组(群组)--pid-path存放进程运行pid文件的路径--conf-path配置文件nginx.conf 的存放路径--error-log-path错误日志error.log的存放路径--http-log-path访问日志access.log的存放路径--with-pcrepcre库的存放路径,正则表达式会用到--with-zlibzlib库的存放路径,gzip模块会用到不指定安装目录,会默认在usr/目录中。比较重要的是pcre跟zlib的库。在nginx内容经常用到正则表达式跟压缩模块gzip。不编译的话,很多子功能放在不同的模块中。内置参数默认原则--with 显示加上,默认不内置 (根据你需要的加上with,比如ssl --with s sl)--without 显示去掉,默认内置编译安装1. 编译前提准备工作下载nginx编译包 (https://nginx.org/en/download.html)下载pcre (ftp://ftp.pcre.org/pub/pcre/)下载zlib (https://www.zlib.net/)然后解压tar -zxvf xx.tar.gz这些目录编译安装1. 安装依赖环境#安装c跟c++的编译器 yum install gcc gcc-c++ #安装openssl yum install openssl openssl-devel #安装gd库 yum install gd gd-devel -y2. 开始编译./configure --hlep 查看帮助cd 到 nginx-1.6.1目录中,再输入 #编译 (并且指定路径 并且 加入pcre/zlib/ssl等扩展) ./configure --prefix=/opt/nginx --conf-path=/opt/nginx/conf/nginx.conf --user=nginx --group=nginx --pid-path=/opt/nginx/pid/nginx.pid --error-log-path=/opt/nginx/logs/error.log --http-log-path=/opt/nginx/logs/access.log --with-pcre=/root/pcre-8.44 --with-zlib=/root/zlib-1.2.11 --with-http_ssl_module --with-http_image_filter_module --with-http_stub_status_module #指定了安装路径、pid路径、日志路径、配置文件路径。参数说明:--prefix (用于指定nginx编译后的安装目录)--add-module (为添加的第三方模块,此次添加了fdfs的nginx模块)--with..._module (表示启用的nginx模块,如此处启用了http_ssl_module模块)这里注意的是:我这pcre扩展、zlib扩展是在上级目录,也就是说nginx压缩包的同级。要不然make时会报错找不到pcre的目录。所以我的--with-pcre=/root/pcre-8.44 --with-zlib=/root/zlib-1.2.11 是这个目录无任何路径的写法如果不加--conf-path、pid-path还有其他的path都可以不指定,这些都会默认放在你的安装nginx的目录下 就是/opt/nginx下反正执行./configure 检查编译的时候,报错了,需要安装什么就去安装什么。*检测编译完。出现这个框就表示ok。并且显示配置或者路径位置信息。3.make编译make make install 就完成了。4. 运行切到nginx的你指定安装目录/opt/nginx ,里有5个目录。[root@localhost nginx]# ll 总用量 4 drwxr-xr-x. 2 root root 4096 12月 17 13:53 conf drwxr-xr-x. 2 root root 40 12月 17 13:53 html drwxr-xr-x. 2 root root 6 12月 17 11:32 logs drwxr-xr-x. 2 root root 6 12月 17 13:53 pid drwxr-xr-x. 2 root root 19 12月 17 13:53 sbin 运行 /opt/nginx/sbin/nginx 就启动了
2020年12月24日
816 阅读
0 评论
0 点赞