認識快取之伺服器快取(Nginx)

2021-09-02 04:18:45 字數 2232 閱讀 1136

不管是前面介紹的apache快取還是現在要介紹的nginx快取,其實他們都借鑑了squid。隨著web伺服器的發展,web伺服器的快取功能已經越來越強大,通過配置使用web伺服器的快取功能,我們在很多時候已經沒有必要去實用squid了。下面是nginx的proxy_cache模組的介紹。

二、nginx快取

1、依賴元件

從nginx-0.7.44版本開始,nginx開始支援類似squid的較正規的快取功能,這個快取是把鏈結用md5編碼經過雜湊後儲存,支援任意鏈結。同時支援404/301/302這樣的非200狀態。在nginx是基於proxy_cache實現的快取功能。

2、nginx安裝ngx_cache擴充套件

make && make install注意:這個是在安裝nginx伺服器的時候,在編譯過程中就需要新增進去。如果後期需要安裝,那麼就需要重新編譯nginx伺服器,將外掛程式編譯進去。

3、nginx cache配置

#擴充套件以php、jsp、cgi結尾的動態應用程式不快取

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

access_log /usr/local/nginx/logs/access.log main;

}}有關快取部分配置詳解:

4、清除快取

清除快取有兩種方法,第一種是直接通過nginx.conf配置檔案定義的/purge虛擬目錄去清除,第二種方法可以通過shell指令碼去批量清楚。下面是shell指令碼清空快取的內容:

#! /bin/sh

#auto clean nginx cache shell scripts

#2013-06-12 wugk

#define path

cache_dir=/data/www/proxy_cache_dir/

file="$*"

#to determine whether the input script,if not, then exit 判斷指令碼是否有輸入,沒有輸入然後退出

if [ "$#" -eq "0" ];then

echo "please insert clean nginx cache file, example: $0 index.html index.js"

sleep 2 && exit

fi echo "the file : $file to be clean nginx cache ,please waiting ....."

for i in `echo $file |sed 's//\n/g'`

do grep -ra $i $| awk -f':' '' > /tmp/cache_list.txt

for j in `cat/tmp/cache_list.txt`

dorm -rf $j

echo "$i $j is deleted success !"

done

done

nginx 之快取伺服器

快取型別 服務端快取 快取 客戶端快取 nginx 快取 配置語法 使用之前需要先定義乙個proxy cache path 配置語法 proxy cache path path levels levels use temp path on off keys zone name size inacti...

Nginx用為快取伺服器

nginx 快取組成 磁碟空間 nginx做為反向 時,能夠將來自upstream的響應快取至本地,並在後續的客戶端請求同樣內容時直接從本地構造響應報文。proxy cache 模組 為上游伺服器提供快取功能 當客戶端再請求時先從快取中找,找到直接發給客戶端 proxy cache path dat...

Nginx做快取伺服器

nginx做快取伺服器 1.主配置 etc nginx nginx.conf 2.proxy配置 etc nginx conf.d proxy.conf 引數解釋 proxy cache path 快取檔案路徑 levels 設定快取檔案目錄層次 levels 1 2 表示兩級目錄 keys zon...