Nginx 模塊
安裝編譯參數(shù)以及作用
編譯選項(xiàng) | 作用 |
---|---|
--with-http_stub_status_module | Nginx 的客戶端狀態(tài) |
--with-http_random_index_module | 目錄中選擇一個(gè)隨機(jī)主頁(yè) |
--with-http_sub_module | HTTP內(nèi)容替換 |
http_stub_status_module配置
Syntax: stub_status;
Default: --
Context: server, location
在/etc/nginx/vhost/test.conf
中加上
.
.
.
location /test {
stub_status;
}
.
.
.
重啟nginx
systemctl restart nginx
在/etc/hosts
文件中加上
127.0.0.1 test.test
image.png
第一行:表示當(dāng)前活躍的連接數(shù)
第二行:1踢械、nginx處理接受的握手次數(shù)安拟,2、nginx所處理的連接數(shù),3军洼、總的請(qǐng)求數(shù)
//正常的話,握手?jǐn)?shù)和連接數(shù)相等,表示數(shù)據(jù)沒有丟失
第三行:狀態(tài):1、讀处坪, 2、寫架专, 3同窘、等待
random_index_module配置
Syntax: random_index on | off;
Default: random_index off;
Context: location
.
.
.
location / {
root /home/chase/test;
random_index on;
}
.
.
.
http_sub_module配置
Syntax: sub_filter string replacement;
Default: --
Context: http, server, location
Syntax: sub_filter_last_modified on | off;
Default: sub_filter_last_modified off;
Context: http, server, location
Syntax: sub_filter_once on | off;
Default: sub_filter_once on;
Context: http, server, location
Nginx的請(qǐng)求限制
連接頻率限制 - limit_conn_module
請(qǐng)求頻率限制 - limit_req_module
http協(xié)議的連接與請(qǐng)求
HTTP協(xié)議版本 | 連接關(guān)系 |
---|---|
HTTP1.0 | TCP不能復(fù)用 |
HTTP1.1 | 順序性TCP復(fù)用 |
HTTP2.0 | 多路復(fù)用TCP復(fù)用 |
HTTP請(qǐng)求建立在一次TCP連接基礎(chǔ)上
一次TCP請(qǐng)求至少產(chǎn)生一次HTTP請(qǐng)求
連接限制配置語(yǔ)法
Syntax: limit_conn_zone key zone=name:size;
Default: --
Context: http
Syntax: limit_conn_zone number;
Default: --
Context: http, server, location
請(qǐng)求限制配置語(yǔ)法
Syntax: limit_req_zone key zone=name:size rate=rate;
Default: --
Context: http
Syntax: limit_req_zone=name [burst=number][nodelay];
Default: --
Context: http, server, location
Nginx的訪問控制
http_access_module配置
//允許
Syntax: allow address | CIDR | unix: | all;
Default: --
Context: http, server, location, limit_except
//不允許
Syntax: deny address | CIDR | unix: | all;
Default: --
Context: http, server, location, limit_except
解決http_access_modules局限性
方法一:采用別的HTTP頭信息控制訪問,如:HTTP_X_FORWARD_FOR
方法二:結(jié)合geo模塊作
方法三:通過HTTP自定義變量傳遞
http_x_forwarded_for配置
http_x_forwarded_for = Client IP, Proxy(1) IP, Proxy(2) IP, ...
http_auth_basic_module配置
Syntax: auth_basic string | off;
Default: auth_basic off;
Context: http, server, location, limit_except
Syntax: auth_basic_user_file file;
Default: --
Context: http, server, location, limit_except
局限性
一:用戶信息依賴文件方式
二:操作管理機(jī)械部脚,效率低下
解決方案
一:Nginx結(jié)合LUA實(shí)現(xiàn)高效驗(yàn)證
二:Nginx和LDAP打通想邦,利用nginx-auth-ldap模塊