Nginx采用模塊化的架構(gòu),Nginx中大部分功能都是通過模塊方式提供的,比如HTTP模塊、Mail模塊等。
Nginx官方模塊文檔
1. ngx_http_stub_status_module編譯選項(xiàng)--with-http_stub_status_module作用
提供Nginx當(dāng)前處理連接等基本狀態(tài)信息的訪問
語法Syntax: stub_status;Default: —Context: server, location用法
在nginx配置文件中的 server 下配置
server { # 添加的配置 location /nginx_status { stub_status; ...其它代碼省略...}
修改后重新載入配置文件nginx -s reload
在瀏覽器中訪問 http:// ip /nginx_status,會返回如下內(nèi)容
Active connections: 3 server accepts handled requests 7 7 16 Reading: 0 Writing: 1 Waiting: 2Active connections: Nginx當(dāng)前活躍鏈接數(shù)
--with-http_random_index_module作用
在主目錄中選擇一個隨機(jī)文件作為主頁
語法Syntax: random_index on | off;Default: random_index off;Context: location用法
在nginx配置文件中的 server 下配置
server { location / { root /usr/share/nginx/html; #添加這一行開啟隨機(jī)主頁模塊 random_index on; #把指定的主頁注釋掉 #index index.html index.htm; ...其它代碼省略...}3. ngx_http_sub_module編譯選項(xiàng)
--with-ngx_http_sub_module作用
通過替換一個指定的字符串來修改響應(yīng)
語法指定被替換的字符和替代字符
Syntax: sub_filter string replacement;Default: —Context: http, server, location
Last-Modified,用于校驗(yàn)服務(wù)端內(nèi)容是否更改,主要用于緩存場景
Syntax: sub_filter_last_modified on | off;Default: sub_filter_last_modified off;Context: http, server, location
默認(rèn)只替換找到的第一個字符串,若替換文本中的所有匹配的字符串,則置為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,返回如下內(nèi)容,會發(fā)現(xiàn)響應(yīng)中所有nginx已經(jīng)替換為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
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,更多相關(guān)內(nèi)容請關(guān)注PHP !
相關(guān)推薦:
關(guān)于php-fpm的進(jìn)程數(shù)管理
為 Nginx 添加模塊的方法
快速搭建Nginx及其基本參數(shù)的配置
以上就是關(guān)于Nginx常用的官方模塊的詳細(xì)內(nèi)容,PHP教程
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。
新聞熱點(diǎn)
疑難解答
圖片精選