nginx—status的使用
开启状态界面(状态页面配置)
开启status:
location /status {stub_status {on | off};allow 172.16.0.0/16;deny all;
}
访问状态页面的方式:http://server_ip/status
状态码 | 表示的意义 |
---|---|
Active connections 2 当前所有处于打开状态的连接数 | |
accepts | 总共处理了多少个连接 |
handled | 成功创建多少握手 |
requests | 总共处理了多少个请求 |
Reading nginx | 读取到客户端的Header信息数,表示正处于接收请求状态的连接数 |
Writing nginx | 返回给客户端的Header信息数,表示请求已经接收完成,且正处于处理请求或发送响应的过程中的连接数 |
Waiting | 开启keep-alive的情况下,这个值等于active - (reading + writing),意思就是Nginx已处理完正在等候下一次请求指令的驻留连接 |
实例
[root@localhost conf]# vim nginx.conf#access_log logs/host.access.log main;location / {root html;index index.html;}location /status {stub_status;}
[root@localhost conf]# nginx
#看见以下界面代表成功了
通过过滤的方式进行监控status
[root@localhost conf]# curl http:/192.168.230.132/status
Active connections: 1
server accepts handled requests3 3 3
Reading: 0 Writing: 1 Waiting: 0
[root@localhost conf]# curl -s http:/192.168.230.132/status |awk 'NR==4'
Reading: 0 Writing: 1 Waiting: 0
[root@localhost conf]# curl -s http:/192.168.230.132/status |awk 'NR==4{print $2}'
0
使用zabbix监控status
#先在从安装下zabbix
[root@localhost src]# cd /usr/local/
[root@localhost local]# tar xf zabbix-5.4.4.tar.gz
[root@localhost local]# cd zabbix-5.4.4
[root@localhost zabbix-5.4.4]# useradd -r -M -s /sbin/nologin zabbix
[root@localhost zabbix-5.4.4]# yum -y install vim wget gcc gcc-c++ make pcre-devel openssl openssl-devel
[root@localhost zabbix-5.4.4]# ./configure --enable-agentLDAP support: noIPv6 support: no***********************************************************
* Now run 'make install' *
* *
* Thank you for using Zabbix! *
* <http://www.zabbix.com> *
***********************************************************
[root@localhost zabbix-5.4.4]# make install
[root@localhost ~]# tr -dc A-Za-z < /dev/urandom | head -c 8 |xargs
sbncsVLR
[root@localhost ~]# cd /usr/local/etc/
[root@localhost etc]# ls
zabbix_agentd.conf zabbix_agentd.conf.d
[root@localhost etc]# vim zabbix_agentd.conf
(注意:这里配置113行和154行的IP是控制端上的,也就是拥有zabbix平台的)113 Server=192.168.230.131
154 ServerActive=192.168.230.131
165 Hostname=sbncsVLR
322 UnsafeUserParameters=1 #值修改为1
525 UserParameter=check_status,/scripts/check_status.sh [root@localhost etc]# zabbix_agentd #编写脚本
[root@localhost scripts]# vim check_status.sh
[root@localhost scripts]# cat check_status.sh
#!/bin/bashcheck_status=$(curl -s 192.168.230.132/status |awk 'NR==4'|awk -F: {'print $4'})if [ $check_status -ge 1 ];thenecho 1
elseecho 0
fi[root@localhost scripts]# chmod +x check_status.sh
[root@localhost scripts]# ll
总用量 4
-rwxr-xr-x 1 root root 128 10月 28 08:47 check_status.sh[root@localhost conf]# pkill zabbix-agent
[root@localhost conf]# ss -anlt
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:10050 0.0.0.0:*
LISTEN 0 128 0.0.0.0:80 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:* #下面是主上面进行测试
[root@localhost ~]# ss -anlt
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 127.0.0.1:9000 0.0.0.0:*
LISTEN 0 128 0.0.0.0:111 0.0.0.0:*
LISTEN 0 128 0.0.0.0:80 0.0.0.0:*
LISTEN 0 32 192.168.122.1:53 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 5 127.0.0.1:631 0.0.0.0:*
LISTEN 0 128 0.0.0.0:10050 0.0.0.0:*
LISTEN 0 128 0.0.0.0:10051 0.0.0.0:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 [::]:111 [::]:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 5 [::1]:631 [::]:*
[root@localhost ~]# zabbix_get -s 192.168.230.132 -k check_status
0
[root@localhost ~]# zabbix_get -s 192.168.230.132 -k check_status
1
rewrite URL重定向
URL组成:
协议+用户+密码+主机(或者域名):prot/URI?query_args (问号前面都是)
rewrite
语法:rewrite regex replacement flag;,如:
rewrite ^/images/(.*\.jpg)$ /imgs/$1 break;
(把/images下的目录的请求发给 /imgs)
[root@localhost conf]# cd /usr/local/nginx/html/
[root@localhost html]# ls
50x.html index.html index.php tset
[root@localhost html]# mkdir images
[root@localhost html]# cd images/
[root@localhost images]# ls
#随便找张照片放上去
[root@localhost images]# ls
[root@localhost images]# ls
0075TGutgy1gvuz5ma0hhj30l816utg4.jpg
[root@localhost images]# mv 0075TGutgy1gvuz5ma0hhj30l816utg4.jpg 1.jpg
[root@localhost images]# ls
1.jpg
直接查找是可以访问到的,结果如下
如果修改了文件名测试下是否还能访问到
[root@localhost html]# mv images/ imgs
[root@localhost html]# ls
50x.html imgs index.html index.php tset#此行让他找到匹配的对象#access_log logs/host.access.log main;location / {root html;index index.html;}location /images { #添加这句rewrite ^/images/(.*\.jpg)$ /imgs/$1 break;}
两种方式访问测试:
此处的$1用于引用(.*.jpg)匹配到的内容,又如:
rewrite ^/bbs/(.*)$ http://www.idfsoft.com/index.html redirect;
常见的flag
flag | 作用 |
---|---|
last |
基本上都用这个flag,表示当前的匹配结束,继续下一个匹配,最多匹配10个到20个 一旦此rewrite规则重写完成后,就不再被后面其它的rewrite规则进行处理 而是由UserAgent重新对重写后的URL再一次发起请求,并从头开始执行类似的过程 |
break |
中止Rewrite,不再继续匹配 一旦此rewrite规则重写完成后,由UserAgent对新的URL重新发起请求, 且不再会被当前location内的任何rewrite规则所检查 |
redirect | 以临时重定向的HTTP状态302返回新的URL |
permanent | 以永久重定向的HTTP状态301返回新的URL(开发用的比较多) |
ginx使用的语法源于Perl兼容正则表达式(PCRE)库,基本语法如下:
标识符 | 意义 |
---|---|
^ | 必须以^后的实体开头 |
$ | 必须以$前的实体结尾 |
. | 匹配任意字符 |
[] | 匹配指定字符集内的任意字符 |
[^] | 匹配任何不包括在指定字符集内的任意字符串 |
l | 匹配 |
() | 分组,组成一组用于匹配的实体,通常会有 |
if
语法:if (condition) {…}
应用场景:
server段
location段
常见的condition
变量名(变量值为空串,或者以“0”开始,则为false,其它的均为true)
以变量为操作数构成的比较表达式(可使用=,!=类似的比较操作符进行测试)
正则表达式的模式匹配操作
~:区分大小写的模式匹配检查
~*:不区分大小写的模式匹配检查
!~和!~*:对上面两种测试取反
测试指定路径为文件的可能性(-f,!-f)
测试指定路径为目录的可能性(-d,!-d)
测试文件的存在性(-e,!-e)
检查文件是否有执行权限(-x,!-x)
基于浏览器实现分离案例
if ($http_user_agent ~ Firefox) {rewrite ^(.*)$ /firefox/$1 break;
}if ($http_user_agent ~ MSIE) {rewrite ^(.*)$ /msie/$1 break;
}if ($http_user_agent ~ Chrome) {rewrite ^(.*)$ /chrome/$1 break;
}
防盗链案例
location ~* \.(jpg|gif|jpeg|png)$ {valid_referers none blocked www.idfsoft.com;if ($invalid_referer) {rewrite ^/ http://www.idfsoft.com/403.html;}
}
nginx—status的使用相关推荐
- nginx生产环境常用功能include 、虚拟主机别名、rewrite、nginx status详细解析
一.配置文件优化之include参数 如果我们用nginx搭建虚拟主机,虚拟主机太多,我们不能把所有配置放置在nginx.conf中吧?那样这个配置文件就太大了,看起来很乱,所有这时就产生了 incl ...
- 启用nginx status状态详解
nginx和php-fpm一样内建了一个状态页,对于想了解nginx的状态以及监控nginx非常有帮助.为了后续的zabbix监控,我们需要先了解nginx状态页是怎么回事. 1. 启用nginx s ...
- Zabbix监控nginx status
nginx开启status ./configure --with-http_stub_status_modulenginx.conflocation /statusx35 {stub_status o ...
- 企业级监控软件使用zabbix key监控nginx status各种状态
因业务需要需要用zabbix来监控nginx status,具体是如下的做法: 1. 首先在nginx的配置文件中添加如下内容,需要注意的是nginx的文件格式,在allow中我们需要注意的是需要添加 ...
- Nginx中配置开启Nginx Status来查看服务器运行状态
1. 启用nginx status配置 大概Nginx配置文件,在默认主机里面加上location或者你希望能访问到的主机里面加上如下配置. location /status { ...
- Nginx 服务器开启status页面检测服务状态
原文:http://www.cnblogs.com/hanyifeng/p/5830013.html 一.Nginx status monitor 和apache 中服务器状态一样.输出的内容如: ...
- php 监控nginx日志,nginx启用status监控服务器状态的方法详解
nginx和php-fpm一样内建了一个状态页,对于想了解nginx的状态以及监控nginx非常有帮助. 在Nginx中的stub_status模块主要用于查看Nginx的一些状态信息.本模块默认是不 ...
- Linux 下Nginx开启status用以监控状态信息
目录 1.通过nginx -V来查看是否有with-http_stub_status_module该模块 2.启用nginx status配置 3.重启nginx 4.打开status页面
- 在CentOS 6.9 x86_64上开启nginx 1.12.2的stub_status模块(ngx_http_stub_status_module)监控
Nginx中的stub_status模块主要用于查看Nginx的一些状态信息. 本模块默认是不会编译进Nginx的,如果你要使用该模块,则要在编译安装Nginx时指定: ./configure -- ...
最新文章
- 服务器传感器不显示,服务器传感器不显示
- 《从paxos到zookeeper》学习笔记(一)
- WPF Calendar 日历控件 样式自定义
- linux添加怎么退出,linux – 是否可以设置’expect’的退出代码
- Linux学习:文件描述符表
- Adb connection Error:远程主机强迫关闭了一个现有的连接
- 在计算机的通信子网中 其操作方式有两种,全国自考计算机网技术模拟试卷(八)及答案.doc...
- 【BZOJ1880】[Sdoi2009]Elaxia的路线 最短路+DP
- linux鼠标选中的内容不能复制,解决vim不能使用鼠标右键复制的问题
- 矮人DOS工具箱 V4.2 安装及使用
- [深度学习]基于TensorFlow的基本深度学习模型
- 通过EasyPOI导入excel数据
- Java语言十五讲(总结)
- 脚本小子_Lua安装教程
- 基于tp5的免费开源企业官网系统
- 高德地图-初始化地图
- 安卓手机连接不上电脑的解决方法 adb devices 找不到设备
- 计算机键盘手指放置,键盘上手指放置的位置图
- YOLO系列之yolo v1
- unity-动画状态机Animator
热门文章
- SQLZOO刷题记录5——SUM and COUNT
- Startup CTO 访谈 | 烧了几个亿学会的创业公司架构演进的正确姿势
- 解决VScode按“感叹号+Tab”和直接按感叹号无法自动生成HTML模板的问题
- 地球35处神秘魅力之地:中国有两处
- MySQL:介于普通读和锁定读的加锁方式,linux视频格式转换
- 知名猎头告诉你员工离职,企业招聘时的猎头费用,谁来买单?
- html导入mybase,mybase用户教程
- Latex中多个作者用同一个地址、一个作者用多个地址等问题(以Elsevier为例)
- 关于 G1(Garbage First)垃圾收集器
- LifeWORK青年技能分享 | 身为别人口中的资源大师,我是如何搜索电子资源的?