免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2141 | 回复: 0
打印 上一主题 下一主题

nginx的缓存问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-08-18 11:36 |只看该作者 |倒序浏览
nginx的缓存问题



  看过张宴先生的文章,使用nginx的proxy_cache取代squid , 然后试验了下,结果发现在缓存时,经常会出现数据缓存了一半的情况,不知道有人知道原因?  测试了nginx0.8.17  和nginx1.1.0  都有这个问题,难道是我配置文件写的有问题,贴出来, 大家帮忙看看。
      nginx.conf:

  1. user  root;
  2. worker_processes  2;
  3. #error_log  logs/error.log;
  4. #error_log  logs/error.log  notice;
  5. #error_log  logs/error.log  info;
  6. #pid        logs/nginx.pid;

  7. worker_rlimit_nofile 65500;
  8. events {
  9.     worker_connections  65500;
  10.     use epoll;
  11. }

  12. http {
  13.     include       mime.types;
  14.     default_type  application/octet-stream;
  15. log_format main '$remote_addr - $remote_user $time_local "$request_method http:
  16. //$host$request_uri HTTP/1.1" $status $bytes_sent "$http_referer" "$http_user_ag
  17. ent" TCP_HIT:NONE $request_time';
  18.     access_log  logs/access.log  main;
  19.     sendfile        on;
  20.     tcp_nopush     on;
  21.     keepalive_timeout  0;
  22.     #keepalive_timeout  65;
  23.     gzip  on;
  24.     gzip_static on;
  25.     gzip_http_version 1.1;
  26.     gzip_min_length  1k;
  27.     gzip_buffers     4 16k;
  28.     gzip_proxied any;
  29.     #gzip_comp_level 5;
  30.     #gzip_disable        "MSIE [1-6]\.";
  31.     #gzip_types   text/plain application/x-javascript text/css application/xml;
  32.     gzip_vary on;
  33.     server_names_hash_bucket_size  128;
  34.     proxy_temp_path  /home/cache_nginx/temp;
  35.     proxy_cache_path /home/cache_nginx/cache levels=1:2  keys_zone=cache_one:500
  36. m inactive=3d max_size=50g;
  37.     include ./david/*.conf;

  38. }

  39.    ./david/test.conf  

  40. upstream www.tt48.com {
  41.     server   192.168.1.56:80 fail_timeout=30s;
  42.   }
  43. server {
  44.         listen       80;
  45. #       server_name  192.168.1.48;
  46.         index index.html index.htm index.php index.asp index.aspx index.jsp;
  47.         root  /home/cache_nginx/cache;  
  48.        location / {
  49.          proxy_next_upstream http_502 http_504 error timeout invalid_header;
  50.                 proxy_cache cache_one;
  51.                 proxy_cache_valid  200 304 20m;
  52.                 proxy_cache_valid  any 5m;
  53.                 proxy_cache_key $host$uri;
  54.                 proxy_set_header Host  $host;
  55.                 proxy_set_header X-Forwarded-For  $remote_addr;
  56.                 proxy_pass http://www.tt48.com;
  57.         add_header X-cache "$upstream_cache_status from gen";
  58.         }
  59.         location ~ .*\? {
  60.                 proxy_set_header Host  $host;
  61.                 proxy_set_header X-Forwarded-For  $remote_addr;
  62.                 proxy_pass http://www.tt48.com;
  63.         add_header X-cache "$upstream_cache_status from wenhao";
  64.         }
  65.         location ~ .*\.(jsp|asp|asps|php|do|action)$ {
  66.                 proxy_set_header Host  $host;
  67.                 proxy_set_header X-Forwarded-For  $remote_addr;
  68.                 proxy_pass http://www.tt48.com;
  69.         add_header X-cache "$upstream_cache_status from asp";
  70.         }
  71.         location ~ .*\.(jpg|html)$ {
  72.                 proxy_cache cache_one;
  73.                 proxy_cache_valid  200 304 2d;
  74.                 proxy_cache_valid  any 1m;
  75.                 proxy_cache_key $host$uri;
  76.                 proxy_set_header Host  $host;
  77.                 proxy_set_header X-Forwarded-For  $remote_addr;
  78.                 proxy_pass http://www.tt48.com;
  79.         add_header X-cache "$upstream_cache_status from jpg";
  80.         }
  81. }
复制代码
192.168..56  这个机器上简单的使用搭建了一个web站点,配置文件就不贴出来了, 没东西,192.168.1.48这台机器在缓存1.56web站点上的图片时会出现缓存一半的情况,返回给用户这个图片就打不开了, 不知道问题出在哪里,也许是配置文件有错,也许是nginx的缓存功能不行....  还请大家帮忙看看,我的配置文件是否有错误

    下面是我做压力测试的图,贴出来看看

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP