Nginx:设置Nginx作为缓存
2016-03-07 18:46
417 查看
一、设置Nginx作为缓存
1.1 完整的配置文件nginx.conf
1.2 测试
curl www.guowenyan.cn/test.html
用户第一次请求一个url,nginx会回源,将结果返回给用户的同时,把结果缓存;
第二次再请求该url时,nginx直接将结果返回给用户,无需回源。
是否回源,我是通过在nginx上抓包看的。
参考资料:
Nginx缓存功能的设置:http://blog.csdn.net/yybjroam05/article/details/21954457
1.1 完整的配置文件nginx.conf
#user nobody; worker_processes 1; events { worker_connections 1024; } http { log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log logs/access.log main; #source site ip and port upstream contactpool{ server 106.38.193.183:80; } #proxy cache info proxy_connect_timeout 5; proxy_read_timeout 60; proxy_send_timeout 5; proxy_buffer_size 16k; proxy_buffers 4 64k; proxy_busy_buffers_size 128k; proxy_temp_file_write_size 128k; proxy_temp_path /home/temp_dir; proxy_cache_path /home/cache levels=1:2 keys_zone=cache_one:50m inactive=20m max_size=30g; server { listen 80; server_name localhost; location / { #proxy cache info index index.html index.htm index.php; proxy_cache cache_one; proxy_cache_valid 200 302 1h; proxy_cache_key $host$uri$is_args$args; proxy_pass http://contactpool; proxy_ignore_headers "Cache-Control" "Expires" "Set-Cookie"; # 不处理后端服务器返回的指定响应头 expires 30d; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } }
1.2 测试
curl www.guowenyan.cn/test.html
用户第一次请求一个url,nginx会回源,将结果返回给用户的同时,把结果缓存;
第二次再请求该url时,nginx直接将结果返回给用户,无需回源。
是否回源,我是通过在nginx上抓包看的。
参考资料:
Nginx缓存功能的设置:http://blog.csdn.net/yybjroam05/article/details/21954457
相关文章推荐
- 关于nginx 配置gzip 压缩js问题 请求合并问题
- nginx安装
- 安装windows 下 php7+nginx+fastcgi
- Mac OS X 10.10 配置 nginx + php
- nginx日志切割
- centos 6.6 Nginx 安装配置(已纠正)
- 【nginx】4xx,5xx 保持自定义header
- 【nginx】4xx,5xx 保持自定义header
- LVS Nginx HAProxy
- nginx密码认证
- Nginx VS HaProxy
- nginx(四)fastcgi相关配置
- tony_nginx_02_URL重写
- Apache与Nginx服务器对比
- nginx实例解析
- 关于什么是nginx配置文件下的location
- Windows下配置Nginx+PHP
- [转] ubuntu+php+nginx 安装
- apache,nginx.iis 从写规则转换
- 【Nginx】事件和连接