您当前的位置: 首页 >  centos

小志的博客

暂无认证

  • 1浏览

    0关注

    1217博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Nginx—— sub_module模块详解(Centos7通过yum方式安装)

小志的博客 发布时间:2021-07-07 22:30:07 ,浏览量:1

目录
    • 一、sub_module的编译参数作用
    • 二、http_sub_module的配置
    • 三、sub_module模块中的配置演示

一、sub_module的编译参数作用 编译选项作用–with-http_sub_moduleHTTP内容替换 二、http_sub_module的配置

1、sub_filter 模块配置语法

  • Syntax:sub_filter string replacement string表示要替换的内容;replacement表示替换后的内容
  • Default:—— 表示默认没有配置
  • Context:http,server,location 表示需要在http块或server块或location块中进行配置

2、sub_filter_last_modified模块配置语法

  • Syntax:sub_filter_last_modified on|off 表示nginx服务端和浏览器客户端进行每次请求时校验服务端的内容是否发生过变更,一般以时间格式记录在http的头信息中,目的是判断是否有更新,如果有更新,返回给客户端最新的内容,主要用于缓存的应用场景。
  • Default:sub_filter_last_modified off 表示默认是关闭的
  • Context:http,server,location 表示需要在http块或server块或location块中进行配置

3、sub_filter_once模块配置语法

  • Syntax:sub_filter_once on|off 表示所有html代码中匹配第一个字符串,
  • Default:sub_filter_once on 表示默认是开启的,on表示匹配所有html中第一个字符串,off表示匹配所有html中所有相同的字符串
  • Context:http,server,location 表示需要在http块或server块或location块中进行配置
三、sub_module模块中的配置演示

1、先创建是一个submodule.html页面,上传到/opt/app/html目录下,以便配置好sub_module模块编译参数后访问/opt/app/html目录下的submodule.html页面,查看替换的内容。

  • submodule.html页面

    
    	
    		
    		submodule
    	
    	
    		html
    		xml
    		json
    		xml
    		jsp
    		html
    	
    
    
  • 浏览器访问如下图

    在这里插入图片描述

2、编辑nginx.conf配置文件

[root@localhost /]# vim /etc/nginx/nginx.conf

在这里插入图片描述 3、在server块的location块中添加如下配置

 #配置sub_module模块
 location /{
           root /opt/app/html;
           sub_filter 'html' 'HTML';
 }

在这里插入图片描述

4、检查配置修改的配置文件是否正确,返回successful表示配置文件修改无错。否则检查配置文件语法。

在这里插入图片描述 5、启动nginx服务

[root@localhost ~]# systemctl start nginx.service

在这里插入图片描述

6、重新加载配置文件

[root@localhost /]# systemctl reload nginx

在这里插入图片描述 7、重启nginx服务

[root@localhost /]# systemctl restart nginx.service

在这里插入图片描述

8、浏览器输入http://localhost/submodule.html 地址,可以看到页面中第一个html已经替换成大写的HTML,如下图:

在这里插入图片描述

9、如何把所有的字符串html都替换成大写

  • 在server块的location块中添加如下配置

    #配置sub_module模块
    location /{
             root /opt/app/html;
             sub_filter 'html' 'HTML';
             sub_filter_once off;
    }
    
  • 6、重新加载配置文件

    [root@localhost /]# systemctl reload nginx
    

    在这里插入图片描述

  • 再次浏览器输入http://localhost/submodule.html 地址,查看页面内容

    在这里插入图片描述

关注
打赏
1661269038
查看更多评论
立即登录/注册

微信扫码登录

0.0465s