您好,欢迎访问一九零五行业门户网

关于Nginx常用的官方模块

这篇文章主要介绍了 关于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
用法在nginx配置文件中的 server 下配置
server {    # 添加的配置    location /nginx_status {        stub_status;    }        ...其它代码省略...}
修改后重新载入配置文件nginx -s reload
在浏览器中访问 http://<ip>/nginx_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
用法在nginx配置文件中的 server 下配置
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
用法在nginx配置文件中的 server 下配置
server {    location / {        root   /usr/share/nginx/html;        index  index.html;        # 将首页的nginx替换为home        sub_filter 'nginx' 'home';        # 不止替换第一个,而是替换response中所有的nginx        sub_filter_once off;    }        ...其它代码省略...}
修改后重新载入配置文件nginx -s reload
curl localhost,返回如下内容,会发现响应中所有nginx已经替换为home
[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 andworking. 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-fpm的进程数管理
为 nginx 添加模块的方法
快速搭建nginx及其基本参数的配置
以上就是关于nginx常用的官方模块的详细内容。
其它类似信息

推荐信息