Nginx反向代理缓存配置
2017-12-25 22:34
288 查看
安装nginx和清理缓存的nginx模块
下载地址https://pan.baidu.com/s/1mi9Xks4
https://pan.baidu.com/s/1i5eVpid
./configure --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --modules-path=/usr/lib64/nginx/modules --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_auth_request_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_stub_status_module --with-http_perl_module=dynamic --with-http_slice_module --with-mail=dynamic --with-mail_ssl_module --with-stream=dynamic --with-stream_ssl_module --with-threads --with-pcre --with-debug --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic' --add-module=../ngx_cache_purge-2.3
make && make install
设置反向代理缓存
proxy_cache_path /usr/share/nginx/cache levels=1:2 keys_zone=one:20m max_size=1g inactive=1d;
#keys_zone指的是缓存空间名称
#max_size指的是缓存文件可以占用的最大空间
#inactive指的是如果一个缓存文件多长时间不被访问,就会被删除
server {
listen 80;
server_name xujx.pw www.xujx.pw;
#charset koi8-r;
access_log /var/log/nginx/cache.access.log;
error_log /var/log/nginx/v363.cn.error.log;
#增加两头部
add_header X-Via $server_addr;
add_header X-Cache $upstream_cache_status;
location / {
proxy_pass http://api.000o.cc/newparse; proxy_set_header X-Real-IP $remote_addr;
proxy_cache_key "$host$request_uri";
proxy_cache one;
proxy_cache_valid 200 302 10m; #页面返回码为200 302 的缓存10分
proxy_cache_valid 404 1m; #页面错误响应吗404缓存时间1分
}
location ~ /purge(/.*) {
proxy_cache_purge one $host$1$is_args$args;
}
}
下载地址https://pan.baidu.com/s/1mi9Xks4
https://pan.baidu.com/s/1i5eVpid
./configure --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --modules-path=/usr/lib64/nginx/modules --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_auth_request_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_stub_status_module --with-http_perl_module=dynamic --with-http_slice_module --with-mail=dynamic --with-mail_ssl_module --with-stream=dynamic --with-stream_ssl_module --with-threads --with-pcre --with-debug --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic' --add-module=../ngx_cache_purge-2.3
make && make install
设置反向代理缓存
proxy_cache_path /usr/share/nginx/cache levels=1:2 keys_zone=one:20m max_size=1g inactive=1d;
#keys_zone指的是缓存空间名称
#max_size指的是缓存文件可以占用的最大空间
#inactive指的是如果一个缓存文件多长时间不被访问,就会被删除
server {
listen 80;
server_name xujx.pw www.xujx.pw;
#charset koi8-r;
access_log /var/log/nginx/cache.access.log;
error_log /var/log/nginx/v363.cn.error.log;
#增加两头部
add_header X-Via $server_addr;
add_header X-Cache $upstream_cache_status;
location / {
proxy_pass http://api.000o.cc/newparse; proxy_set_header X-Real-IP $remote_addr;
proxy_cache_key "$host$request_uri";
proxy_cache one;
proxy_cache_valid 200 302 10m; #页面返回码为200 302 的缓存10分
proxy_cache_valid 404 1m; #页面错误响应吗404缓存时间1分
}
location ~ /purge(/.*) {
proxy_cache_purge one $host$1$is_args$args;
}
}
相关文章推荐
- 【Linux】Nginx反向代理/缓存配置
- 使用Nginx反向代理与proxy_cache缓存搭建CDN服务器的配置方法
- Nginx反向代理缓存配置
- 使用Nginx反向代理与proxy_cache缓存搭建CDN服务器的配置方法
- 使用Nginx反向代理与proxy_cache缓存搭建CDN服务器的配置方法
- nginx反向代理,页面缓存,虚拟主机等快速配置
- nginx反向代理,负载均衡,缓存的配置文件,带注释
- RHEL6.3配置DNS服务器(2) 配置缓存域名服务器和转发
- hibernate如何配置二级缓存
- AndroidStudio 缓存文件夹配置
- spring+hibernate 二级缓存 配置+java使用实例
- Fresco(Facebook开源的android项目)图片缓存框架的eclipse整合与使用探索(较详细配置说明)
- spring中配置hibernate二级缓存
- spring中配置二级缓存
- Apache配置静态缓存
- 第三节:工厂+反射+配置文件(手写IOC)对缓存进行管理。
- Android杂谈(11)更换Androidstudio缓存配置目录,减少c盘压力
- Oracle Coherence中文教程十七:缓存配置案例
- Windows下Magento企业版如何配置Redis存储缓存
- Microsoft Enterprise Library 5.0 缓存配置