三、配置反向代理缓存:
nginx : 192.168.80.146
web1:192.168.80.143
web1配置:
# yum -y install httpd # echo "web1" > /var/www/html/index.html # service httpd startnginx配置:
# egrep -v "^$|#" /etc/nginx/nginx.conf worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; proxy_cache_path /var/www/cache levels=1:2 keys_zone=mycache:20m max_size=2048m inactive=60m; //指定缓存目录/var/www/cache,levels定义缓存级别,缓存名字mycache,最大缓存2048M,非活动时间 proxy_temp_path /var/www/cache/tmp; //临时缓存目录 sendfile on; keepalive_timeout 65; server { listen 80; server_name localhost; location / { proxy_pass ; //指定web服务器 proxy_cache mycache; //指定前面定义的缓存名字 proxy_cache_valid 200 302 60m; //定义http协议200,302 的缓存60min proxy_cache_valid 404 1m; //http协议404缓存1min } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } } # mkdir -p /var/www/cache # service nginx restart配置好了以后先访问先80.146看到是默认nginx的页面:
之后我们启动服务开始代理,在访问80.146看到的后端web1的页面: