Nginx常用的基礎配置

2021-10-08 13:21:09 字數 2069 閱讀 8615

nginx的客戶端狀態 http_stub_status

syntax: stub_status;

default:

context: server,location

#示例:

location /mystatus

目錄中選擇乙個隨機頁面展示 http_random_index

syntax: random_index on|off;

default: random_index off;

context: location

連線限制

請求限制

context: http,server,location示例

#連線限制

limit_conn_zone $binary_remote_addr zone=conn_zone:1m;

limit_conn conn_zone 1; #同一時刻,只允許乙個ip的連線請求過來

#請求限制

linit_req_zone $binary_remote_addr zone=req:1m rate=1r/s;

limit_req zone=req_zone; #同乙個ip,1s只允許發起1個請求

limit_req zone=req_zone burst=3 nodelay; #3個延時處理,其餘的該咋樣咋樣

nginx的訪問控制(通過ip)http_access

syntax: allow(deny) address|cidr|unix|all;

default:

context: http,server,location,limit except

侷限性:只能通過remote_addr控制信任,如果使用**,起不到對原機器的控制。

解決侷限性:

採用別的http頭資訊訪問控制,如http_x_forward_for(有原機器以及途中機器的ip)

結合geo模組作

通過http自定義變數傳遞

nginx訪問控制:auth_basic_module (需要輸入使用者名稱密碼訪問)

context: http,server,location,limit except示例

#安裝密碼加密外掛程式htpasswd

# htpasswd -c ./auth_conf jeson #jeson為使用者名稱

auth_basic "auth access test! input your password!";

auth_basic_user_file /etc/nginx/auth_conf;

侷限性

使用者資訊依賴檔案方式

操作管理機械,效率低下

Nginx基礎語法及常用配置

nginx一般為開箱即用,除了nginx.conf,其餘配置檔案,一般只需要使用預設提供即可。全域性塊 worker process 表示工作程序的數量,一般設定為cpu的核數 worker connections 表示每個工作程序的最大連線數 events events塊 http http塊 每...

常用的nginx 配置

user wwwwww nginx 使用的使用者及使用者組 也有些人用 user nobody 這個使用者 worker processes8 8個worker 一般和核心數一樣 全域性錯誤日誌 可設定日誌級別,及pid檔案 error log logs error.log 這是相對目錄,也可以用絕...

nginx常用配置

官檔 nginx的負載均衡主要依賴這個模組 ngx http upstream module 1 安裝好nginx 192.168.1.111 2 修改egrep v nginx.conf.default nginx.conf 對其進行修改 訪問server name的時候,會找listen埠,所有...