nginx常用模組

2021-10-01 08:45:05 字數 3380 閱讀 2352

需要的伺服器角色

外網ip

內網ip

主機名web

eth0:10.0.0.7

eth1:172.16.1.7

web01

autoindex 目錄索引

[root@web01 ~]

# cat /etc/nginx/conf.d/mirror.oldxu.com.conf

server

}[root@web01 ~]

# mkdir /code/

[root@web01 ~]

# cat /code/index.html

"" target=

"_blank"

>centos系統

"" target=

"_blank"

>ubuntu系統

訪問控制:

基於ip實現訪問控制

10.0.0.1 僅允許訪問 /centos

10.0.0.100 拒絕訪問 /ubuntu , 其他的ip都允許

root@web01 ~

]# cat /etc/nginx/conf.d/mirror.oldxu.com.conf

server

location /centos

location /ubuntu

}

基於使用者名稱和密碼的訪問控制:

}限速

[root@web01 ~]

# cat /etc/nginx/conf.d/mirror.oldxu.com.conf

limit_req_zone $binary_remote_addr zone=req_one:10m rate=1r/s;

limit_conn_zone $binary_remote_addr zone=addr:10m;

server

location /centos

}

案列
[root@web01 ~

]# cat /etc/nginx/conf.d/mirror.oldxu.com.conf

limit_req_zone $binary_remote_addr zone=req_one:

10m rate=

1r/s;

limit_conn_zone $binary_remote_addr zone=addr:

10m;

server

location /download

#接收丟擲504的異常,交給內部 @error_504 處理

error_page 504 @error_504;

location @error_504

}

nginx七中狀態 stub_stauts狀態

含義active connections

當前活躍連線數,包括waiting等待連線數。

accepts

已接收的總tcp連線數量。

handled

已處理的tcp連線數量。

requests

當前總http請求數量。

reading

當前讀取的請求頭數量

writing

當前響應的請求頭數量

waiting

當前等待請求的空閒客戶端連線數

#狀態監控模組

location = /nginx_status

location匹配規則

}nginx 日誌

訪問日誌 記錄使用者請求的資訊

錯誤日誌 記錄所有錯誤資訊,便於後期排查

server
狀態

含義$remote_addr

# 記錄客戶端ip位址 user --> web

$remote_user

# 記錄客戶端使用者名稱

$time_local

# 記錄通用的本地時間

$time_iso8601

# 記錄iso8601標準格式下的本地時間

$request

# 記錄請求的方法以及請求的http協議

$status

# 記錄請求狀態碼(用於定位錯誤資訊)

$body_bytes_sent

# 傳送給客戶端的資源位元組數,不包括響應頭的大小

$bytes_sent

# 傳送給客戶端的總位元組數

$msec

# 日誌寫入時間。單位為秒,精度是毫秒。

# 記錄從哪個頁面鏈結訪問過來的

# 記錄客戶端瀏覽器相關資訊

#記錄客戶端ip位址

$request_length

# 請求的長度(包括請求行, 請求頭和請求正文)。

$request_time

# 請求花費的時間,單位為秒,精度毫秒

# $remote_addr獲取的是反向**的ip位址。 反向**伺服器在**請求的http頭資訊中,

# 增加x-forwarded-for資訊,用來記錄客戶端ip位址和客戶端請求的伺服器位址。

nginx常用模組歸納

目錄 nginx功能詳解.2 一 proxy pass.2 二 rewrite.3 三 log format.4 四 ssl證書加密配置.5 五 sendfile.6 六 keepalive timeout.7 七 gzip.7 八 客戶端上傳檔案限制.7 九 worker processes和wo...

Nginx常用的模組

nginx能做什麼 反向 負載均衡 http伺服器 動靜分離 正向 以上就是我了解到的nginx在不依賴第三方模組能處理的事情,下面詳細說明每種功能怎麼做。反向 下面貼上一段簡單的實現反向 的 儲存配置檔案後啟動nginx,這樣當我們訪問localhost的時候,就相當於訪問localhost 80...

Nginx 常用模組介紹

nginx 核心模組介紹 標準的http功能模組集合 常用模組彙總 ngx http core module 包括一些核心的http引數配置,對應nginx的配置為http區塊部分 ngx http gzip module 壓縮模組,對nginx返回的資料壓縮,屬於效能優化模組 ngx http p...