zoukankan      html  css  js  c++  java
  • 第四节 Nginx缓存服务器

     用户体验

    •  页面打开速度
    •  良好的界面体验
    •  高质量量的内容
    •  个性化内容推送

    页面打开速度
    •  带宽
    •  服务器器的响应速度
    •  传输距离
    •  网络延迟

     

     

    Nginx安装?
    •  Nginx包获得(http://nginx.org)
    http://nginx.org/download/nginx-1.15.8.tar.gz
    •  缓存模块包下载(http://labs.frickle.com/files/)
    http://labs.frickle.com/files/ngx_cache_purge-2.3.tar.gz
    •  安装Nginx

    Nginx缓存部署 
    •  开启缓存
    •  缓存一个网站

    安装Nginx

    nginx源码包
    [root@web01 ~]# wget http://nginx.org/download/nginx-1.15.8.tar.gz
    •  nginx缓存模块
    [root@web01 ~]# wget http://labs.frickle.com/files/ngx_cache_purge-2.3.tar.gz
    •  新建nginx管理理账号
    [root@web01 ~]# useradd -r www -s /sbin/nologin
    •  nginx安装---解压源码包
    [root@web01 ~]# tar xf nginx-1.15.8.tar.gz
    [root@web01 ~]# tar xf ngx_cache_purge-2.3.tar.gz
    •  nginx安装---安装依赖
    [root@web01 ~]# yum -y install pcre-* openssl-*
    •  nginx安装---配置nginx
    [root@web01 ~]# cd nginx-1.15.8
    [root@web01 nginx-1.15.8]# ./configure --prefix=/usr/local/nginx --user=www --group=www --add-module=../ngx_cache_purge-2.3 --with-http_stub_status_module
    •  nginx安装---编译
    [root@web01 nginx-1.15.8]# make –j4
    •  nginx安装---安装
    [root@web01 nginx-1.15.8]# make install

    chown www.www nginx -R

     修改启动Nginx的用户 

    进入config

    修改noboby为 www

    开启缓存
    在http配置中添加
    1)设置缓存临时路路径
    proxy_temp_path /cache/proxy_temp_dir;
    2)缓存路路径及开启
    proxy_cache_path /cache/proxy_dir levels=1:2 keys_zone=cache0:10m inactive=1d max_size=30g;
    #levels=1:2 缓存目录分为两级 第一级⽂文件夹命名用一个字母 第级文件夹用两个字母命名,最多三级。
    #keys_zone=cache0:10m 内存缓存区域10M 名字为cache0。在共享内存中设置一块存储区域来存放缓存的key
    和metadata,这样nginx可以快速判断一个request是否命中或者未命中缓存,1m可以存储8000个key,10m可以存储80000个key
    #inactive=1d 有效期为1天,如果缓存内容在一天中没人访问则被删除
    #max_size=30g 硬盘空间中的30G做磁盘缓存,如果不不指定,会使用掉所有disk space,当达到配额后,会删除最少使用的cache文件

    创建文件夹

    mkdir -p  /cache/proxy_temp_dir

    chown www.www /cache -R

    location / {
      proxy_pass http://www.ayitula.com;
      proxy_cache cache0;
      proxy_cache_valid 200 304 30m;
      proxy_cache_valid any 1m;
      proxy_cache_key $host$uri$is_args$args;
      proxy_set_header Host $host;
      proxy_set_header X-Forwarded-For $remote_addr;
      expires 60m;
    }

     修改config文件

    保存退出

    打开http://192.168.0.143/ 页面展示为 

     

    如果不展示则关闭防火墙

     

     

    location ~/purge(/.*)
    {
    allow 127.0.0.1;
    allow 192.168.11.0/24;
    proxy_cache_purge cache0 $host$1$is_args$args;
    }

    清理缓存

     

    Nginx镜像服务器

    开启缓存
    #本地目录
    root /usr/local/nginx/html;
    index index.html index.php;
    proxy_store on; #开启镜像服务
    proxy_store_access user:rw group:rw all:r; #缓存本地存储⽂文件的权限
    proxy_temp_path /usr/local/nginx/html/temp; #本地临时缓存⽬目录
    #判断本地⽬目录中是否有⽂文件,没有就去取源
    if ( !-e $request_filename ) {
    proxy_pass http://download.ayitula.com;
    }

    编辑config文件

    保存退出启动 

     

  • 相关阅读:
    在jQuery中Ajax的Post提交中文乱码的解决方案
    mysql 日期时间型的按日期分组
    mysql 逗号分隔的id转为逗号分隔的名称
    阿米在日本工作生活趣事(2)
    阿米在日本工作生活趣事(1)
    com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException: Lock wait timeout exceeded; try restarting transaction
    File exists.If no other git process is currently running,
    带小数点的String 转int java.lang.Double cannot be cast to java.lang.Integer
    Jboss解决只能通过localhost访问而不能使用IP访问项目的问题
    This method accesses the value of a Map entry, using a key that was retrieved from a keySet iterator. It is more efficient to use an iterator on the entrySet of the map, to avoid the Map.get(key) look
  • 原文地址:https://www.cnblogs.com/zhanleishang/p/10667735.html
Copyright © 2011-2022 走看看