您的位置:首页 > 运维架构 > 反向代理

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;
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息