nginx web快取配置

2021-06-20 05:00:26 字數 692 閱讀 8186

**:

1.場景:使用proxy_cache快取web靜態內容檔案和通過rewrite偽靜態化後的html整頁面快取。

動態內容通過ajax動態獲取,也保持內容一致。 

2.nginx 配置

a.新增快取檔案儲存路徑

vi /etc/nginx/nginx.conf

#注:proxy_temp_path和proxy_cache_path指定的路徑必須在同一分割槽

proxy_temp_path /cache/proxy_temp_path;

#設定web快取區名稱為cache_one,記憶體快取空間大小為200mb,1天沒有被訪問的內容自動清除,硬碟快取空間大小為30gb。

proxy_cache_path /cach/proxy_cache_path levels=1:2 keys_zone=cache_one:200m inactive=5m max_size=30g;

b.新增快取配置

}#php檔案請求**給後端 

location ~ .*\.(php|cgi)?$

3.過載nginx

sudo service nginx reload

訪問頁面,檢視快取目錄是否生成快取檔案

nginx web伺服器配置

定義nginx執行的使用者和使用者組 user www www nginx程序數,建議設定為等於cpu總核心數。worker processes 8 全域性錯誤日誌定義型別,debug info notice warn error crit error log ar loginx error.log...

Nginx Web服務應用

nginx下面用原始碼安裝nginx tar zxf nginx 1.12.0.tar.gz cd nginx 1.12.0 cd mnt nginx 1.12.0 vim src core nginx.h 隱藏nginx使用的版本號 yum install pcre devel openssl d...

Nginx Web工作原理

nginx web伺服器最主要就是各種模組的工作。1 從結構上分為核心模組 基礎模組 第三方模組 核心模組 http模組 event模組 mail模組等 基礎模組 http access模組 http fastcgi模組 http proxy模組和http rewrite模組 第三方模組 http ...