• 技术文章 >后端开发 >php教程

    关于Nginx常用的官方模块

    不言不言2018-07-13 16:08:17原创963
    这篇文章主要介绍了 关于Nginx常用的官方模块,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下

    Nginx常用官方模块

    Nginx采用模块化的架构,Nginx中大部分功能都是通过模块方式提供的,比如HTTP模块、Mail模块等。

    Nginx官方模块文档

    1. ngx_http_stub_status_module

    编译选项

    --with-http_stub_status_module

    作用

    提供Nginx当前处理连接等基本状态信息的访问

    语法

    Syntax:        stub_status;
    Default:    —
    Context:    server, location

    用法

    server {
        # 添加的配置
        location /nginx_status {
            stub_status;
        }
        
        ...其它代码省略...
    }
    Active connections: 3 
    server accepts handled requests
     7 7 16 
    Reading: 0 Writing: 1 Waiting: 2
    Active connections: Nginx当前活跃链接数
    accepts: 接收客户端连接的总次数
    handled: 处理客户端连接的总次数。一般来说,这个参数值与accepts相同,除非已经达到了一些资源限制(例如worker_connections限制)
    requests: 客户端请求的总次数
    Reading: 当前nginx正在读取请求头的连接数
    Writing: 当前nginx正在写入响应的连接数
    Reading: 当前正在等待请求的空闲客户端连接数。一般是在nginx开启长连接(keep alive)情况下出现。

    2. ngx_http_random_index_module

    编译选项

    --with-http_random_index_module

    作用

    在主目录中选择一个随机文件作为主页

    语法

    Syntax:        random_index on | off;
    Default:    random_index off;
    Context:    location

    用法

    server {
        location / {
            root /usr/share/nginx/html;
            #添加这一行开启随机主页模块
            random_index on;
            #把指定的主页注释掉
            #index index.html index.htm;
        }
        
        ...其它代码省略...
    }

    3. ngx_http_sub_module

    编译选项

    --with-ngx_http_sub_module

    作用

    通过替换一个指定的字符串来修改响应

    语法

    指定被替换的字符和替代字符

    Syntax:    sub_filter string replacement;
    Default:   —
    Context:    http, server, location

    Last-Modified,用于校验服务端内容是否更改,主要用于缓存场景

    Syntax:       sub_filter_last_modified on | off;
    Default:   sub_filter_last_modified off;
    Context:    http, server, location

    默认只替换找到的第一个字符串,若替换文本中的所有匹配的字符串,则置为off

    Syntax:       sub_filter_once on | off;
    Default:    sub_filter_once on;
    Context:    http, server, location

    除了“text/html”之外,还可以用指定的MIME类型替换字符串。特殊值‘*’匹配任意MIME类型

    Syntax:       sub_filter_types mime-type ...;
    Default:    sub_filter_types text/html;
    Context:    http, server, location

    用法

    server {
        location / {
            root   /usr/share/nginx/html;
            index  index.html;
            # 将首页的nginx替换为home
            sub_filter 'nginx' 'home';
            # 不止替换第一个,而是替换response中所有的nginx
            sub_filter_once off;
        }
        
        ...其它代码省略...
    }
    [vagrant/etc/nginx]$ curl localhost
    <!DOCTYPE html>
    <html>
    <head>
    <title>Welcome to home!</title>
    <style>
        body {
            width: 35em;
            margin: 0 auto;
            font-family: Tahoma, Verdana, Arial, sans-serif;
        }
    </style>
    </head>
    <body>
    <h1>Welcome to home!</h1>
    <p>If you see this page, the home web server is successfully installed and
    working. Further configuration is required.</p>
    
    <p>For online documentation and support please refer to
    <a href="http://home.org/">home.org</a>.<br/>
    Commercial support is available at
    <a href="http://home.com/">home.com</a>.</p>
    
    <p><em>Thank you for using home.</em></p>
    </body>
    </html>

    以上就是本文的全部内容,希望对大家的学习有所帮助,更多相关内容请关注PHP中文网!

    相关推荐:

    以上就是关于Nginx常用的官方模块的详细内容,更多请关注php中文网其它相关文章!

    声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
    上一篇:关于php-fpm的进程数管理 下一篇:Nginx请求限制和访问控制的解析
    20期PHP线上班

    相关文章推荐

    • 【活动】充值PHP中文网VIP即送云服务器• php 生成缩略图程序_PHP教程• PHP无限分类实例程序_PHP教程• PHP重定向的3种方式_PHP教程• php实现文件下载更能介绍_PHP教程• PHP文件上传后缀名与文件类型对照表整理_PHP教程
    1/1

    PHP中文网