nginx緩存及壓縮模塊

一、nginx緩存   共享內存(存儲鍵和緩存對象元數據)  磁盤空間(存儲數據)

    提示:proxy_cache_path:不能定義在server{ }中緩存目錄: 

    (1)先全局定義 proxy_cache_path /nginx/cache/first levels=1:2:1     keys_zone=first:20m max_size=16g;

 

server {

        listen       80;

        server_name  www.cqelpay.com;

add_header X-Via $server_addr;

add_header X-Cache $upstream_cache_status;   添加緩存命中狀態F12,查看

    (2)location中去引用:   

          location / {

          # # root   html;

          # # index  index.html index.jsp;

          proxy_pass http://www.cqelpay.com;

  proxy_cache first;

  proxy_cache_valid 200 302 10m;

  proxy_cache_valid 301 1h;

  proxy_cache_valid 404 1m;

  proxy_cache_valid any 1m;

  }

    (3)另外三種緩存:

          open_log_cache:日誌緩存

  open_file_cache:文件緩存

  fastcgi_cache:


二、gzip壓縮:提示;不懂最好不用

    gzip  on;    #開啓gzip壓縮

    gzip_min_length  1k; 

    gzip_buffers     4 16k;  

    gzip_http_version 1.1; 

    gzip_comp_level 2; 

    gzip_types       text/plain application/x-javascript text/css application/xml; 

    gzip_vary on;


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章