免费注册 查看新帖 |

Chinaunix

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

大家帮我看下,我的nginx缓存配置是不是有问题? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-08-25 11:56 |只看该作者 |倒序浏览
在测试环境下搭建了一台nginx加两台tomcat的负载均衡配置,测试后发现效果一般,现在想配置下nginx的缓存,再重新测试,我的nginx.conf配置如下:
user  www www;
worker_processes 4;
error_log  /usr/local/nginx/logs/nginx_error.log  debug;
pid    /usr/local/nginx/logs/nginx.pid;
worker_rlimit_nofile 65535;
events
{
    use epoll;
    worker_connections 65535;
}
http
{
    include       mime.types;
    default_type  application/octet-stream;
    #charset  gb2312;
   
    server_names_hash_bucket_size 128;
    client_header_buffer_size 32k;
    large_client_header_buffers 4 32k;
    sendfile on;
    tcp_nopush     on;
    keepalive_timeout 60;
    tcp_nodelay on;

    fastcgi_temp_path  /opt/proxy_temp_path;
    fastcgi_cache_path  /opt/proxy_cache_path levels=1:2 keys_zone=cache_one:200m  inactive=1d max_size=10g;
   
    gzip on;
    gzip_min_length  1k;
    gzip_buffers     4 16k;
    gzip_http_version 1.0;
    gzip_comp_level 2;
    gzip_types       text/plain application/x-javascript text/css application/xml;
    gzip_vary on;
    gzip_proxied any;

    upstream  tomcats  {
        server   192.168.131.57:8081;
        server   192.168.131.56:8081;
    #    server   192.168.131.61:8080;
    }
    server
    {
        listen  81;
        server_name localhost;
        proxy_redirect off;
     
  
      location / {
                proxy_pass   http://tomcats;
                expires 12h;
        }
     #扩展名以.gif、.jpg、.css等结尾的静态文件缓存。

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css|html|jsp)$

        {

        fastcgi_cache cache_one;  
        fastcgi_cache_valid 200 304 12h;  
        fastcgi_cache_valid 301 302 1m;
        fastcgi_cache_valid any 1m;
        fastcgi_cache_key $host$uri$is_args$args;
        proxy_set_header  Host $host;
        proxy_set_header  X-Real-IP  $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        add_header X-Cache "HIT from cache_test";
        add_header Age "1";
        proxy_set_header Accept-Encoding "none";
        proxy_ignore_headers "Cache-Control" "Expires";
        proxy_pass http://tomcats;
        expires  1h;
        }

  #扩展名以.php、.jsp、.cgi结尾的动态应用程序不缓存。

        location ~ .*\.(php|cgi)?$  {
        proxy_set_header  Host $host;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_pass http://tomcats;
        }


        location ~ ^/NginxStatus {
        stub_status on;
        access_log off;
        if (-d $request_filename){
        rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;
        }
        }
   
        location ~ ^/(WEB-INF)/ {
        deny all;
        }
      
   #设置只允许指定的IP或IP段才可以清除URL缓存。
        location ~ /purge(/.*)  {
        allow            127.0.0.1;
        allow            192.168.0.0/16;
        allow             all;
        }   

        error_page  500 502 503 504  /50x.html;
        location = /50x.html {
        root   html;
        }

        log_format  access  '$remote_addr - $remote_user [$time_local] $request '
                   '"$status" $body_bytes_sent "$http_referer" '
                   '"$http_user_agent" "$http_x_forwarded_for"';
        access_log  /usr/local/nginx/logs/access.log  access;
        client_max_body_size     300m;
        client_body_buffer_size  512k;
        proxy_connect_timeout    600;
        proxy_read_timeout       600;
        proxy_send_timeout       600;
        proxy_buffer_size        16k;
        proxy_buffers            4 64k;
        proxy_busy_buffers_size 128k;
        proxy_temp_file_write_size 128k;
  
    }
}

我用这个加了缓存的nginx配置,重新测试,效果和之前没加缓存的差不多,是不是我的缓存配置失败了呢?还有,如果通过缓存去访问了,有没有相关日志能看到呢?

论坛徽章:
59
2015七夕节徽章
日期:2015-08-24 11:17:25ChinaUnix专家徽章
日期:2015-07-20 09:19:30每周论坛发贴之星
日期:2015-07-20 09:19:42ChinaUnix元老
日期:2015-07-20 11:04:38荣誉版主
日期:2015-07-20 11:05:19巳蛇
日期:2015-07-20 11:05:26CU十二周年纪念徽章
日期:2015-07-20 11:05:27IT运维版块每日发帖之星
日期:2015-07-20 11:05:34操作系统版块每日发帖之星
日期:2015-07-20 11:05:36程序设计版块每日发帖之星
日期:2015-07-20 11:05:40数据库技术版块每日发帖之星
日期:2015-07-20 11:05:432015年辞旧岁徽章
日期:2015-07-20 11:05:44
2 [报告]
发表于 2010-08-25 12:40 |只看该作者
我在WEB服务器版块发了一本关于NGINX的书。楼主下来看看。

论坛徽章:
0
3 [报告]
发表于 2010-08-25 13:16 |只看该作者
回复 2# renxiao2003


    去WEB那找了,没找到呀。。。

    求地址。。。。

    重要的是先谢谢!

论坛徽章:
59
2015七夕节徽章
日期:2015-08-24 11:17:25ChinaUnix专家徽章
日期:2015-07-20 09:19:30每周论坛发贴之星
日期:2015-07-20 09:19:42ChinaUnix元老
日期:2015-07-20 11:04:38荣誉版主
日期:2015-07-20 11:05:19巳蛇
日期:2015-07-20 11:05:26CU十二周年纪念徽章
日期:2015-07-20 11:05:27IT运维版块每日发帖之星
日期:2015-07-20 11:05:34操作系统版块每日发帖之星
日期:2015-07-20 11:05:36程序设计版块每日发帖之星
日期:2015-07-20 11:05:40数据库技术版块每日发帖之星
日期:2015-07-20 11:05:432015年辞旧岁徽章
日期:2015-07-20 11:05:44
4 [报告]
发表于 2010-08-25 17:22 |只看该作者
http://bbs.chinaunix.net/thread-1771919-1-1.html

好明显的,你居然没有看见。晕了。呵呵。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP