nginx模塊詳解

nginx模塊詳解

大家好,我是酷酷的韓~
在這裏插入圖片描述
一.模塊分類

1.官方模塊

官方提供的 例如nginx.org網站上提供的所有~

2.第三方模塊

第三方提供的或自己寫的稱爲第三方模塊。

3.通過nginx -V 可進行查看
在這裏插入圖片描述
二.模塊詳解
1.–with-http_stub_status_module

(1)含義: nginx的客戶端狀態

(2)配置語法:

Synax:stub_status
Default:-
Context:server,location

(3)操作,在/etc/nginx/conf.d/default.conf中,新增

 location /substatus{
      stub_status;
   }

(4)新增完重新加載

nginx -s reload -c /etc/nginx/nginx.conf

會有少部分人會問,爲什麼修改的是default.conf,重新加載的是nginx.conf呢? 因爲nginx.conf加載的同時會去加載default.conf ,詳情可去另外一篇博客:https://blog.csdn.net/hjq_ku/article/details/89383278

(5)瀏覽器訪問
在這裏插入圖片描述
2.–with-http_random_index_module

(1)含義:目錄選擇一個隨機主頁

(2)配置語法:

Synax:random_index on |off
Default: random_index_off;
Context:location

3.with-http_sub_module

(1)含義:

http內容替換,替換一些html中的內容

(2)配置語法:

替換第一個字段

Synax: sub_filter string replacement
Default:-
Context: http server location

判斷是否有更新,有更新返回用戶最新的 如果沒更新,不需要再次返回相同的html (nginx緩存)

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

匹配所有html代碼裏面的第一個還是匹配所有指定字符串(on第一個 off所有指定)

Synax:sub_filter_once on|off
Default:sub_filter_once on
Context:http,server,location

(3)運用:
在/opt/app/code 目錄下有一index.html文件,內容如下:

在default.conf中修改(注意,每句之間用;)

location / {
        root   /opt/app/code;
        index  index.html index.htm;
        sub_filter '<a>java' '<a>JAVA';
        sub_filter_once off;
    }

其中 sub_filter ‘java’ ‘JAVA’;將html中第一個’java’ 修改爲 ‘JAVA’
sub_filter_once 默認爲on on時 則只會修改第一個 off 會修改所有。(不是a1 是a 編輯的時候有點小bug)
(4)瀏覽器訪問:
在這裏插入圖片描述
要成功,先發瘋,頭腦簡單向前衝。------酷酷的韓

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章