免费注册 查看新帖 |

Chinaunix

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

Nginx架设一个高效的缓存转发 [复制链接]

论坛徽章:
2
丑牛
日期:2013-09-29 09:47:222015七夕节徽章
日期:2015-08-21 11:06:17
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-11-04 09:38 |只看该作者 |倒序浏览
作/译者:吴炳锡 来源:
http://coolriver.cublog.cn
,wubingxi#gmail.com 转载请注明作/译者和出处,并且不能用于商业用途,违者必究。
仿F5的工作
项目情况:
  用户上传的音乐需在播放,音乐量比较大.同时用户上传的音乐命不会重名.不用过期.

Squid
和Varnish在高负载时,会出现无响应的现象.内网流量较大.
Nginx
在这点上说明:
以前用F5觉的比较牛的就是可以
缓存
转发,感觉功能挺牛的.没钱买F5,只好用Nginx顶一把了.nginx可以说不算一个Cache,他不存在过期的问题.
Let's Go:
假架倒是很简单,也可以和
负载均衡
再一台机器上.
机器的
硬盘
要大一点.根据数据大小来定吧.
这里只提一个方法[不推荐用这个,所以写的简单点]
利用404,405的处理方法.
定义后端的Server,按分组的概念:
  upstream music_ser{
                server 172.16.100.10:80 weight=1;
                server 172.16.100.11:80 weight=1;
}
定义一个Server:
server {
        listen 80;
        server_name music.wubx.com;
        access_log  /data/logs/music_access.log
        proxy_temp_path /data/Cache/temp;
        root /data/Cache/$host;
        location / {
                index index.php;
                error_page 404 = /fetch$uri;
        }
        location /fetch {
                internal;
                proxy_pass http://music_ser;
                proxy_store on;
                proxy_store_access user:rw group:rw all:rw;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header Via "nginx";
                alias /data/Cache/$host;
        }
}
完成配置nginx.conf
===================================
user  nobody;
worker_processes  1;
error_log  /data/logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
#pid        logs/nginx.pid;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream
        sendfile        on;
        keepalive_timeout  65;
upstream music_ser{
     server 172.16.100.10:80 weight=1;
     server 172.16.100.11:80 weight=1;
}
server {
        listen 80;
        server_name music.wubx.com;
        access_log  /data/logs/music_access.log
        proxy_temp_path /data/Cache/temp;
        root /data/Cache/$host;
        location / {
                index index.php;
                error_page 404 = /fetch$uri;
        }
        location /fetch {
                internal;
                proxy_pass http://music_ser;
                proxy_store on;
                proxy_store_access user:rw group:rw all:rw;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header Via "nginx";
                alias /data/Cache/$host;
        }
}
}
用一个
脚本
去除理常放置时间长的
文件
:
mkdir /data/Cache
mkdir /data/Cache/temp
chown -R nobody:nobody /data/Cache
fine /data/Cache/$host -type -atime 30 |xargs rm -rf {}\
$host换成你域名
根据路径在做调整.
把那个加到Cron中吧.
上线观察中.

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/4206/showart_1358900.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP