Nginx模块讲解
Nginx模块分为:nginx官方模块、第三方模块
通过nginx -V查看编译参数,可以看到官方编译的模块
--with-compat
--with-file-aio
--with-threads
--with-http_addition_module
--with-http_auth_request_module
--with-http_dav_module
--with-http_flv_module
--with-http_gunzip_module
--with-http_gzip_static_module
--with-http_mp4_module
--with-http_random_index_module
--with-http_realip_module
--with-http_secure_link_module
--with-http_slice_module
--with-http_ssl_module
--with-http_stub_status_module
作用:nginx的客户端连接状态
Syntax:stub_status;
Default:——
Context:server,location
--with-http_sub_module
--with-http_v2_module
--with-mail
--with-mail_ssl_module
--with-stream
--with-stream_realip_module
--with-stream_ssl_module
--with-stream_ssl_preread_module
--with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong
--param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC'
--with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'
--with-http_stub_status_module
作用:nginx的客户端连接状态
Syntax:stub_status
Default:——
Context:server,location
演示:
vi /etc/nginx/conf.d/default.conf
配置如图下:
location /mystatus {
stub_status;
}

使用配置是否正确
nginx -tc /etc/nginx/nginx.conf
然后重载服务
nginx -s reload -c /etc/nginx/nginx.conf
在浏览器中输入ip+路径
http://192.168.96.188/mystatus

Active connections: 1 #当前活跃的连接数
server accepts handled requests
1 1 1 # 第一个值代表握手总次数;第二个值代理处理的连接数;第三个值是总的请求数;(握手次数一般都等于连接数,代表连接没有丢失)
Reading: 0 Writing: 1 Waiting: 0 #读、写、等待
--with-http_random_index_module
作用:目录中选择一个随机主页
Syntax:random_index on | off
Default:random_index off
Context:location
演示:
在/opt/app/code目录下定义3个html文件1.html、2.html、3.html
分别复制如下代码
<html>
<head>
<meta charset="utf-8">
<title>imooc1</title>
</head>
<body style=""> # 红色
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>imooc1</title>
</head>
<body style=""> #黑色
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>imooc1</title>
</head>
<body style=""> #蓝色
</body>
</html>
修改配置文件
vi /etc/nginx/conf.d/default.conf
location / {
root /opt/app/code;
random_index on;
#index index.html index.htm;
}

查看配置是否正确
nginx -tc /etc/nginx/nginx.conf
然后重载服务
nginx -s reload -c /etc/nginx/nginx.conf
在浏览器中访问ip,刷新页面就会变颜色了

--with-http_sub_module
作用:http内容替换
#1语法
Syntax:sub_filter string replacement
Default:——
Context:http,server,location
#2语法
Syntax:sub_filter_last_modified on|off
Default:sub_filter_last_modified off
Context:server,location
#3语法
Syntax:sub_filter_last_once on | off
Default:sub_filter_last_once on
Context:http,server,location
演示:
在/opt/app/code目录下添加html文件
复制如下代码,保存
<html>
<head>
<meta charset="utf-8">
<title>submodules</title>
</head>
<body>
<a>joy</a>
<a>at</a>
<a>imooc</a>
<a>joy</a>
<a>imooc</a>
</head>
</body>
</html>
访问 192.168.96.188/submodule.html。
通过配置语法替换“imooc“”的内容为“IMOOC_JOY”

vi /etc/nginx/conf.d/default.conf
加入下列代码
location / {
root /opt/app/code;
index index.html index.htm;
sub_filter '<a>imooc' '<a>IMOOC_JOY'; #sub_filter 后面添加需要替换内容,已经替换后的内容
}
访问 192.168.96.188/submodule.html
默认只替换一个

如果替换全部,加入新的语法
location / {
root /opt/app/code;
index index.html index.htm;
sub_filter '<a>imooc' '<a>IMOOC_JOY';
sub_filter_once off; #在原有基础加上此模块,off 关闭
}
保存访问地址,记得强刷或者清理缓存,此时内容全部替换

Nginx模块讲解的更多相关文章
- nginx 模块讲解
1. 通用配置选项: --prefix=<path> 指定Nginx的安装路径,所有其他的路径都要依赖于该选项 --sbin-path=<path> ...
- 【转】Nginx模块开发入门
转自: http://kb.cnblogs.com/page/98352/ 结论:对Nginx模块开发入门做了一个helloworld的示例,简单易懂.也有一定的深度.值得一看. Nginx模块开发入 ...
- Nginx模块开发入门
前言 Nginx是当前最流行的HTTP Server之一,根据W3Techs的统计,目前世界排名(根据Alexa)前100万的网站中,Nginx的占有率为6.8%.与Apache相比,Nginx在高并 ...
- [转] Nginx模块开发入门
前言 Nginx是当前最流行的HTTP Server之一,根据W3Techs的统计,目前世界排名(根据Alexa)前100万的网站中,Nginx的占有率为6.8%.与Apache相比,Nginx在高并 ...
- Nginx模块开发入门(转)
前言 Nginx是当前最流行的HTTP Server之一,根据W3Techs的统计,目前世界排名(根据Alexa)前100万的网站中,Nginx的占有率为6.8%.与Apache相比,Nginx在高并 ...
- Nginx模块开发入门(转)
前言 Nginx是当前最流行的HTTP Server之一,根据W3Techs的统计,目前世界排名(根据Alexa)前100万的网站中,Nginx的占有率为6.8%.与Apache相比,Nginx在高并 ...
- Nginx模块
模块概述 https://kb.cnblogs.com/page/98352/ Nginx模块工作原理概述 (Nginx本身支持多种模块,如HTTP模块.EVENT模块和MAIL模块,本文只讨论HTT ...
- FW: Nginx模块开发入门
前言 Nginx是当前最流行的HTTP Server之一,根据W3Techs的统计,目前世界排名(根据Alexa)前100万的网站中,Nginx的占有率为6.8%.与Apache相比,Nginx在高并 ...
- Nginx 模块开发
Nginx 模块概述 Nginx 模块有三种角色: 处理请求并产生输出的 Handler 模块 : 处理由 Handler 产生的输出的 Filter (滤波器)模块: 当出现多个后台 服务器时, ...
随机推荐
- C# 如何在项目引用x86 x64的非托管代码
因为现在的项目使用的是 AnyCpu 在 x86 的设备使用的是x86,在x64使用的是x64,但是对于非托管代码,必须要在x64使用x64的dll,在x86使用x86的dll.在C++没有和C#一样 ...
- Linux 内核bin+attribute 结构二进制属性
sysfs 惯例调用所有属性来包含一个单个的人可读文本格式的值. 就是说, 只是偶然地很 少需要来创建能够处理大量二进制数据的属性. 这个需要真正地只出现在必须传递数据, 不可动地, 在用户空间和设备 ...
- JS 手札记
addEventListener中的事件如果移除(removeEventListener)的话不能在事件中执行bind(this)否则会移除无效! // selectCurrent() // copy ...
- <sUbjeCt>Reverse aAlignment SemInaR
翻译过来就是有关逆序对问题的专题. 因为大胆报名担任学校专题讲师所以跪着也要准备好课件...那什么是逆序对? 逆序对就是序列中ai>aj且i<j的有序对 举个栗子: 其中,5>4,但 ...
- Python 多组输入
#基于Python2.7 #若是想Python做到和C++中while(scanf()!=EOF)一样的多组输入效果,可以如实例所示书写 #实例实现了多组输入,计算A+B+C并输出的任务 while ...
- 22.json&pickle&shelve
转载:https://www.cnblogs.com/yuanchenqi/article/5732581.html json 之前我们学习过用eval内置方法可以将一个字符串转成python对象,不 ...
- Kubernetes从私有镜像仓库中拉取镜像
当我们尝试从私有仓库中拉取镜像时,可能会收到这样提示:requested access to the resource is denied Error response from daemon: pu ...
- 从头学pytorch(十一):自定义层
自定义layer https://www.cnblogs.com/sdu20112013/p/12132786.html一文里说了怎么写自定义的模型.本篇说怎么自定义层. 分两种: 不含模型参数的la ...
- 洛谷$P4503\ [CTSC2014]$企鹅$QQ$ 哈希
正解:哈希 解题报告: 传送门$QwQ$ 直接$O(len)$枚举哪一位,然后把这一位删了重新拼接起来,存桶里查下就成 $over$? 主要的难点大概在卡哈希+卡常$QAQ$ #include< ...
- js的class基础
title: js的class基础 date: 2020-01-04 13:34:44 tags: --- 基本写法 let log = console.log; class people { con ...