对我的许多不同的网络服务器的担忧

时间:2015-11-13 11:14:15

标签: webserver varnish ip-camera varnish-vcl varnish-4

我有几个网络摄像头,希望它通过Varnish的流量。

每个网络摄像头都有自己的网络服务器。我想首先到达,当我登录cam.city.travel:4444/cam1/然后显示相机1并在页面cam.city.travel:4444/cam2/然后相机2和下一个。

当我使用网站时,cam.city.travel:4444 / cam1 /重播了cam.city.travel:4444/cgi-bin/image.html中的地址栏。当我插入/ cam1 /(cam.city.travel:4444/cam1/cgi-bin/image.html)时,只出现页面的一部分。缺少示例图像。

图片的链接是 cam.city.travel:4444/picture/current.jpg

到目前为止,我的想法对Varnish不起作用或不可行?

我使用的以下配置:

    #
    # varnish configuration
    #
    vcl 4.0;

    backend cam01 { .host = "xxx.xxx.xxx.xx1"; .port = "80"; }
    backend cam02 { .host = "xxx.xxx.xxx.xx2"; .port = "80"; }
    backend cam03 { .host = "xxx.xxx.xxx.xx3"; .port = "80"; }
    backend cam04 { .host = "xxx.xxx.xxx.xx4"; .port = "80"; }
    backend cam05 { .host = "xxx.xxx.xxx.xx5"; .port = "80"; }

    sub vcl_recv {
        set req.http.x-host = req.http.host;
        set req.http.x-url = req.url;
        set req.http.x-ip = server.ip;
        set req.http.x-port = std.port(server.ip);

        if (req.http.host == "cam.city.travel:4444") 
          {
           if (req.url ~ "^/cam01/") { set req.url = 
    regsub(req.url, "^/cam01/", "/"); set req.backend_hint = cam01; }
           if (req.url ~ "^/cam02/") { set req.url = 
    regsub(req.url, "^/cam02/", "/"); set req.backend_hint = cam02; }
           if (req.url ~ "^/cam03/") { set req.url = 
    regsub(req.url, "^/cam03/", "/"); set req.backend_hint = cam03; }
           if (req.url ~ "^/cam04/") { set req.url = 
    regsub(req.url, "^/cam04/", "/"); set req.backend_hint = cam04; }
           if (req.url ~ "^/cam05/") { set req.url = 
    regsub(req.url, "^/cam05/", "/"); set req.backend_hint = cam05; }

           set req.http.x-backend = req.backend_hint;
           return (pass);
        }
    }

1 个答案:

答案 0 :(得分:0)

听起来你可以将循环方法与导演一起使用,如下所示:

director cameras round-robin {
        {
                .backend = cam01;
        }
        {
                .backend = cam02;
        }
        {
                .backend = cam03;
        }
        {
                .backend = cam04;
        }
        {
                .backend = cam05;
        }
}

sub vcl_recv {
   if (req.http.host ~ "^cam.city.travel$") {
       set req.backend = cameras;
   }
} 

参考:https://www.varnish-cache.org/trac/wiki/LoadBalancing