当前位置: > Linux服务器 > nginx >

nginx做图片访问分发

时间:2016-02-02 18:10来源:未知 作者:IT
nginx version: nginx/0.8.33

需求如下:

http://img.test.com/20100330/80/01/12614801/a.jpg ->a机器
http://img.test.com/20100330/60/01/12614801/a.jpg ->b机器



url规则是:http://域名/日期/1级存放目录/2级存放目录/图片文件
我现在是想判断url的1级目录字段,(我的1级目录字段是0-9,a-f)根据字段不的不同,让用户访问到不同的机器:譬如 0-7字符的目录访问b机器8,9,a-f访问到a机器

nginx的配置文件如下:

user  root root;

worker_processes 50;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
error_log  logs/error.log  info;
pid        nginx.pid;

worker_rlimit_nofile 51200;

events
{
      use epoll;

      worker_connections 51200;
}

http
{
      include       mime.types;
      default_type  application/octet-stream;

      keepalive_timeout 120;

      tcp_nodelay on;

      upstream  img1  {
              server   192.168.118.216:80;
      }

      upstream  img6  {
              server   182.168.118.221:80;
      }

      server
      {
              listen  80;
              server_name  img1.test.com;
#       }

        location / {
                if ($uri ~* ^/[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]/[0-7][0-9a-f]/) {
                proxy_pass http://img1;
                break;
                        }
                if ($uri ~* ^/[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]/[89a-f][0-9a-f]/) {
                proxy_pass http://img6;
                break;
                }
        }
                location /NginxStatus {
                        stub_status             on;
                        access_log              on;
                        auth_basic              “NginxStatus”;
                        auth_basic_user_file  htpasswd;
                }

              access_log  /Data/logs/www.log;
      }

}
(责任编辑:IT)
------分隔线----------------------------
栏目列表
推荐内容