八、Nginx WEB模块
1.1 stub_status_moudule
目的 :展示用户和nginx链接数量信息。
#查询模块是否安装
[root@xuleilinux ~]# nginx -V 2>&1 | grep stub_status
--with-http_stub_status_module
启动状态模块,默认该功能没启动
#在server下面编写
location /nginx_status {
stub_status;
allow all;
}
"注意空格"
重启服务登录
192.168.238.132/nginx_status
F5刷新
分表代表:1:总连接数 1:成功连接数 9:总共处理的请求数
Active connections: 1 当前活动的连接数
server accepts handled requests
服务器接受处理请求
Reading: 0 读取客户端Header的信息数 请求头
Writing: 1 返回给客户端的header的信息数 响应头
Waiting: 0 等待的请求数,开启了keepalive
1.1.1 关于链接的问题
什么是链接
1.2 随机主页
ramdom_index_module
目的:将主页设置成随机页面,是一种微调更新机制
- 创建主页目录 mkdir /app
- 创建多个主页
/app/{
blue.html,green.html,red.html,.yellow.html}
#在不同页面写不同的内容,eg:
<html>
<head>
<title>green color</title>
</head>
<body style="background-color:green">
<h1>green color!</h1>
</body>
</html>
- 启动随机主页
vim /etc/nginx/conf.d/default.conf
server{
#在server里面添加
location / {
#root /usr/share/nginx/html;
#index index.html index.htm;
root /app;
random_index on;
}
}
重启
F5刷新
注意隐藏文件并不会被随机选取
需要调用:app.com/yellow.html
1.3 替换模块
sub_module
目的:网页内容替换
如果我们用模板生成网站的时候,因为疏漏或者别的原因造成代码不如意,但是此时因为文件数量巨大,不方便全部重新生成,那么这个时候我们就可以用此模块来暂时实现纠错。另一方面,我们也可以利用这个实现服务器端文字过滤的效果。(当服务器断电或者出错,可以快速使用此模块替换)
vim /etc/nginx/conf.d/default.conf 启动nginx默认页面
server {
sub_filter nginx 'QianFeng';
sub_filter_once on;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
重启服务
1.4 文件读取
ngx_http_core_module
语法:
Syntax:sendfile on | off;
Default:sendfile on;
Context:http,server,location,if in location
Syntax: tcp_nopush on | off;
Default: tcp_nopush off;
Context: http, server, location
Syntax: tcp_nodelay on | off;
Default: tcp_node