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模块讲解的更多相关文章

  1. nginx 模块讲解

    1. 通用配置选项: --prefix=<path>          指定Nginx的安装路径,所有其他的路径都要依赖于该选项 --sbin-path=<path>     ...

  2. 【转】Nginx模块开发入门

    转自: http://kb.cnblogs.com/page/98352/ 结论:对Nginx模块开发入门做了一个helloworld的示例,简单易懂.也有一定的深度.值得一看. Nginx模块开发入 ...

  3. Nginx模块开发入门

    前言 Nginx是当前最流行的HTTP Server之一,根据W3Techs的统计,目前世界排名(根据Alexa)前100万的网站中,Nginx的占有率为6.8%.与Apache相比,Nginx在高并 ...

  4. [转] Nginx模块开发入门

    前言 Nginx是当前最流行的HTTP Server之一,根据W3Techs的统计,目前世界排名(根据Alexa)前100万的网站中,Nginx的占有率为6.8%.与Apache相比,Nginx在高并 ...

  5. Nginx模块开发入门(转)

    前言 Nginx是当前最流行的HTTP Server之一,根据W3Techs的统计,目前世界排名(根据Alexa)前100万的网站中,Nginx的占有率为6.8%.与Apache相比,Nginx在高并 ...

  6. Nginx模块开发入门(转)

    前言 Nginx是当前最流行的HTTP Server之一,根据W3Techs的统计,目前世界排名(根据Alexa)前100万的网站中,Nginx的占有率为6.8%.与Apache相比,Nginx在高并 ...

  7. Nginx模块

    模块概述 https://kb.cnblogs.com/page/98352/ Nginx模块工作原理概述 (Nginx本身支持多种模块,如HTTP模块.EVENT模块和MAIL模块,本文只讨论HTT ...

  8. FW: Nginx模块开发入门

    前言 Nginx是当前最流行的HTTP Server之一,根据W3Techs的统计,目前世界排名(根据Alexa)前100万的网站中,Nginx的占有率为6.8%.与Apache相比,Nginx在高并 ...

  9. Nginx 模块开发

    Nginx 模块概述 Nginx 模块有三种角色: 处理请求并产生输出的 Handler 模块 : 处理由  Handler  产生的输出的 Filter (滤波器)模块: 当出现多个后台 服务器时, ...

随机推荐

  1. UVa 1635 - Irrelevant Elements-[分解质因数]

    Young cryptoanalyst Georgie is investigating different schemes of generating random integer numbers ...

  2. linux进程 阻塞和非阻塞操作

    在我们看全功能的 read 和 write 方法的实现之前, 我们触及的最后一点是决定何时使 进程睡眠. 有时实现正确的 unix 语义要求一个操作不阻塞, 即便它不能完全地进行下去. 有时还有调用进 ...

  3. ASP.NET MVC4.0+EF+LINQ+bui+网站+角色权限管理系统(7)

    今天将使用Simplemembership进行权限控制 我们使用mvc的AuthorizeAttribute来实现对Controller and Action权限控制 看如下标为红色的代码片段: // ...

  4. C# 多线程的等待所有线程结束

      //前台线程和后台线程唯一区别就是:应用程序必须运行完所有的前台线程才可以退出://而对于后台线程,应用程序则可以不考虑其是否已经运行完毕而直接退出,//所有的后台线程在应用程序退出时都会自动结束 ...

  5. [HNOI2019]白兔之舞

    memset0 多合一无聊题 mod k=t,并且k是p-1的约数 单位根反演石锤了. 所以直接设f[i]表示走i步的方案数, 然后C(L,i)分配位置,再A^i进行矩乘得到f[i] 变成生成函数F( ...

  6. 【15.93%】【codeforces 672D】Robin Hood

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  7. GapMinder气泡图:在线互动图表数据平台

    GapMinder:在线互动图表数据平台是一个将国际统计数据转换成活动的.交互的和有趣的图表,以在线统计数据为基础的互动图表集的完美世界.目的是通过增进对可以自由访问的公共统计数据的使用和理解,以促进 ...

  8. hive查询中文乱码问题

    问题1. hue中中文字符乱码问题,重现步骤如下 create external table test_1_txt (id int, name varchar(100))  location '/tm ...

  9. windows添加右键菜单

    哔哔 有时候想要用websotrm打开一个项目, 有时候想要用VScode打开,最快的方法就是右键指定打开方式了 这些软件安装的时候会自带,但如果有些软件没有自带右键项,就得去注册表里手动添加 这些东 ...

  10. 30分钟全方位了解阿里云Elasticsearch(附公开课完整视频)

    摘要: 阿里云Elasticsearch提供100%兼容开源Elasticsearch的功能,以及Security.Machine Learning.Graph.APM等商业功能,致力于数据分析.数据 ...