大约图如下:

NGINX FRONT(80)--->VARNISH(8080)---->LNMP BACKEND 1(80)

|--->LNMP BACKEND 2(80)

主要是前两个的配置文件:

NGINX-FRONT:

#user  nobody;
worker_processes  ;

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

#pid        logs/nginx.pid;

events {
    worker_connections  ;
}

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

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  ;
    keepalive_timeout  ;

    #gzip  on;
    upstream  mylocalsite {
     server   ;
    } 

    server {
        listen       ;
        server_name  192.168.1.101;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
             proxy_pass http://mylocalsite;
        }

        #error_page                /.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page        /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   ;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }

    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       ;
    #    listen       somename:;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

    # HTTPS server
    #
    #server {
    #    listen        ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

VARNISH:

 backend server1 {
     .host = "192.168.1.102";
     .port = ";

 }
 backend server2 {
     .host = "192.168.1.102";
     .port = ";

 }

director myvarnish round-robin {
 { .backend = server1; 

}
 { .backend = server2;
}
 }
 sub vcl_recv {

     if (req.http.host !~ "www\.myvarnish\.com$"){
    error  "Unknown HostName!";
        } else {
    set req.backend = myvarnish;
     }
     ) {
     if (req.http.x-forwarded-for) {
         set req.http.X-Forwarded-For =
         req.http.X-Forwarded-For + ", " + client.ip;
     } else {
         set req.http.X-Forwarded-For = client.ip;
     }
     }
     if (req.request != "GET" &&
       req.request != "HEAD" &&
       req.request != "PUT" &&
       req.request != "POST" &&
       req.request != "TRACE" &&
       req.request != "OPTIONS" &&
       req.request != "DELETE") {
         /* Non-RFC2616 or CONNECT which is weird. */
         return (pipe);
     }
     if (req.request != "GET" && req.request != "HEAD") {
         /* We only deal with GET and HEAD by default */
         return (pass);
     }
     if (req.http.Authorization || req.http.Cookie) {
         /* Not cacheable by default */
         return (pass);
     }
     return (lookup);
 }

 sub vcl_pipe {

     return (pipe);
 }

 sub vcl_pass {
     return (pass);
 }

 sub vcl_hash {
     hash_data(req.url);
     if (req.http.host) {
         hash_data(req.http.host);
     } else {
         hash_data(server.ip);
     }
     return (hash);
 }

 sub vcl_hit {
     return (deliver);
 }

 sub vcl_miss {
     return (fetch);
 }

 sub vcl_fetch {
     if (beresp.ttl <= 0s ||
         beresp.http.Set-Cookie ||
         beresp.http.Vary == "*") {
         /*
          * Mark as "Hit-For-Pass" for the next 2 minutes
          */
          s;
         return (hit_for_pass);
     }
     return (deliver);
 }

 sub vcl_deliver {
     return (deliver);
 }

 sub vcl_error {
     set obj.http.Content-Type = "text/html; charset=utf-8";
     ";
     synthetic {"
 <?xml version="1.0" encoding="utf-8"?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 <html>
   <head>
     <title>"} + obj.status + " " + obj.response + {"</title>
   </head>
   <body>
     <h1>Error "} + obj.status + " " + obj.response + {"</h1>
     <p>"} + obj.response + {"</p>
     <h3>Guru Meditation:</h3>
     <p>XID: "} + req.xid + {"</p>
     <hr>
     <p>Varnish cache server</p>
   </body>
 </html>
 "};
     return (deliver);
 }

 sub vcl_init {
     return (ok);
 }

 sub vcl_fini {
     return (ok);
 }

NGINX-BACKEND:

#user  nobody;
worker_processes  ;

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

pid        logs/nginx.pid;

events {
    worker_connections  ;
}

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

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  ;
    keepalive_timeout  ;

    #gzip  on;

    server {
        listen       ;
        #server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   ;
            index  index.html index.htm index.php;
        }

        #error_page                /.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page        /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on
        #
        location ~ \.php$ {
         root ;
         fastcgi_pass   ;
               fastcgi_index  index.php;
             fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
             include        fastcgi_params;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }

    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    server {
        listen       ;
        #listen       localhost:;
    #    server_name  somename  alias  another.alias;

        location / {
            root   ;
            index  index.html index.htm;
        }
      location ~ \.php$ {
         root ;
         fastcgi_pass   ;
               fastcgi_index  index.php;
             fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
             include        fastcgi_params;
        }
    }

    # HTTPS server
    #
    #server {
    #    listen        ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

WINDOWS下用VMLITE WORKSTATION测试,资源耗费真的不多呢。

测试WWW方案(反向代理,负载均衡,HTTP加速缓存)的更多相关文章

  1. Nginx特性验证-反向代理/负载均衡/页面缓存/URL重定向

    原文发表于cu:2016-08-25 参考文档: Nginx 反向代理.负载均衡.页面缓存.URL重写等:http://freeloda.blog.51cto.com/2033581/1288553 ...

  2. 反向代理负载均衡之nginx

    一.集群 1.1 什么是集群 集群是一组相互独立的.通过高速网络互联的计算机,它们构成了一个组,并以单一系统的模式加以管理.一个客户与集群相互作用时,集群像是一个独立的服务器.集群配置是用于提高可用性 ...

  3. 如何使用Weave以及Docker搭建Nginx反向代理/负载均衡服务器

    Hi, 今天我们将会学习如何使用 Weave 和 Docker 搭建 Nginx 的反向代理/负载均衡服务器.Weave 可以创建一个虚拟网络将 Docker 容器彼此连接在一起,支持跨主机部署及自动 ...

  4. 项目实战2.2—nginx 反向代理负载均衡、动静分离和缓存的实现

    实验一:实现反向代理负载均衡且动静分离 1.环境准备: 机器名称 IP配置 服务角色 备注 nginx VIP:172.17.11.11 反向代理服务器 开启代理功能 设置监控,调度 rs01 RIP ...

  5. Nginx 反向代理 负载均衡 虚拟主机配置

    Nginx 反向代理 负载均衡 虚拟主机配置 通过本章你将学会利用Nginx配置多台虚拟主机,清楚代理服务器的作用,区分正向代理和反向代理的区别,搭建使用Nginx反向搭理和负载均衡,了解Nginx常 ...

  6. nginx 详解反向代理负载均衡

    什么是反向代理负载均衡 使用代理服务器可以将请求转发给内部的Web服务器,使用这种加速模式显然可以提升静态网页的访问速度.因此也可以考虑使用这种技术,让代理服务器将请求 均匀转发给多台内部Web服务器 ...

  7. Nginx 反向代理 负载均衡 虚拟主机

    Nginx 反向代理 负载均衡 虚拟主机配置 通过本章你将学会利用Nginx配置多台虚拟主机,清楚代理服务器的作用,区分正向代理和反向代理的区别,搭建使用Nginx反向搭理和负载均衡,了解Nginx常 ...

  8. 十.nginx反向代理负载均衡服务实践部署

    期中集群架构-第十章-nginx反向代理负载均衡章节章节====================================================================== 0 ...

  9. 项目实战2.1—nginx 反向代理负载均衡、动静分离和缓存的实现

    总项目流程图,详见 http://www.cnblogs.com/along21/p/8000812.html 实验一:实现反向代理负载均衡且动静分离 1.环境准备: 机器名称 IP配置 服务角色 备 ...

  10. 项目实战02:nginx 反向代理负载均衡、动静分离和缓存的实现

    目录 实验一:实现反向代理负载均衡且动静分离 1.环境准备: 2.下载编译安装tengine 3.设置代理服务器的配置文件 4.启动tengine服务 5.开启后端的web服务 6.测试 实验二:ng ...

随机推荐

  1. WS_CLIPCHILDREN和WS_CLIPSIBLINGS的理解(转载)

    1.1 WS_CLIPCHILDREN WS_CLIPCHILDREN样式从字面上可以理解成ClipChildren,裁减子窗口. MSDN里的E文解释:Excludes the area occup ...

  2. AndroidStudio怎么将开源项目发布到jcenter

    前言 自己在网上搜了一大堆,大体就两种方法,而我选择的是其中代码少的的方法,不过他们或多或少留下了少许的坑,(按他们的方法我是上传成功,但不能发布到jCenter上去,也可能是我自己的问题o(≧v≦) ...

  3. 【Android】数据库的简单应用——增删改查的操作

    还记得getReadableDatabase()和getWritableDatabase()方法吧?在调用它们的时候会返回一个SQLiteDatabase对象,借助这个对象就可以进行CURD(Crea ...

  4. Ubuntu16.04下Intellij IDEA不能输入中文的问题

    最近Ubuntu升级到16.04后发现IDEA的中文输入法不能正常切换了. 之前用的是fcitx安装的输入法, 折腾了半天才解决. 只需要修改idea.sh文件即可. 不需要折腾fcitx中的配置. ...

  5. 过滤器(filter)实现用户登录拦截

    过滤器(filter)实现用户登录拦截 >>>>>>>>>>>>>>>>>>>> ...

  6. nginx之服务器

    Nginx ("engine x") 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器. Nginx 是由 Igor Sysoev ...

  7. React+Immutable.js的心路历程

    这段时间做的项目开发中用的是React+Redux+ImmutableJs+Es6开发,总结了immutable.js的相关使用姿势: Immutable Data 顾名思义是指一旦被创造后,就不可以 ...

  8. vim 编辑器笔记

    vim 编辑器 命令模式(默认),尾行模式 : / 两种方式 (Esc比较慢,连续连词esc,删除全部尾行内容),编辑模式 a,i,o,s :q 退出编辑不保存 :wq 保存编辑并退出 :w 保存并写 ...

  9. php快速排序

    快速排序是排序中常用的,效率据说还不错,它使用分治算法实现 将一个大的需要排序的序列,分成两个较小的序列!怎么分呢,需要从序列中找出一个元素作为参考元素,通常的做法是拿第一个元素作为参考元素.当一个序 ...

  10. 文件上传利器SWFUpload使用指南

    这里就不再介绍什么是SWFUpload啦,简单为大家写一个简单关于SWFUpload的Demo. 1.把SWFUpload 相关的文件引用进来 2.创建upload.aspx页面(页面名称可自定义), ...