测试WWW方案(反向代理,负载均衡,HTTP加速缓存)-阿里云开发者社区

开发者社区> 天飞> 正文

测试WWW方案(反向代理,负载均衡,HTTP加速缓存)

简介: 大约图如下: NGINX FRONT(80)--->VARNISH(8080)---->LNMP BACKEND 1(80)                                                               |--->LNMP BACKEND 2(80)...
+关注继续查看

大约图如下:

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

                                                              |--->LNMP BACKEND 2(80)

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

NGINX-FRONT:

#user  nobody;
worker_processes  1;

#error_log  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;

    #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  0;
    keepalive_timeout  65;

    #gzip  on;
    upstream  mylocalsite {  
     server   192.168.1.103:8080;
    } 

    server {
        listen       80;
        server_name  192.168.1.101;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
             proxy_pass http://mylocalsite;
        }

        #error_page  404              /404.html;

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

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

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    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       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

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


    # HTTPS server
    #
    #server {
    #    listen       443 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 = "80";

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

 }

director myvarnish round-robin {
 { .backend = server1; 
  
}
 { .backend = server2; 
}
 }
 sub vcl_recv {


     if (req.http.host !~ "www\.myvarnish\.com$"){ 
    error 404 "Unknown HostName!"; 
        } else {
    set req.backend = myvarnish;
     }
     if (req.restarts == 0) {
     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
          */
         set beresp.ttl = 120 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";
     set obj.http.Retry-After = "5";
     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  1;

#error_log  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;

    #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  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        #server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

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

        #error_page  404              /404.html;

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

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        location ~ \.php$ {
         root 80;
         fastcgi_pass   127.0.0.1:9000;
               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       8080;
        #listen       localhost:8080;
    #    server_name  somename  alias  another.alias;

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


    # HTTPS server
    #
    #server {
    #    listen       443 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测试,资源耗费真的不多呢。

 

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
使用Nginx反向代理和proxy_cache缓存搭建CDN服务器加快Web访问速度
碰到问题:移动用户访问web服务器www.osyunwei.com很慢解决办法:1、在移动机房放置一台nginx反向代理服务器2、通过域名DNS智能解析,所有移动用户访问www.osyunwei.com时解析到nginx反向代理服务器3、nginx反向代理服务器与web服务器之间采用专线连接系统运维  www.
1637 0
如何让App首屏启动更快 -- httpdns持久化缓存方案
httpdns作为解决域名劫持,调度不精准问题的一剂良药,很大程度上改善了app的用户体验。为了追求更加极致的性能体验,本文推出httpdns持久化缓存方案,让app首屏启动更快!
151 0
jQuery EasyUI API 中文文档 - 加载器
EasyLoader  加载器 用法 1. easyloader.base = '../';    // 设置easyui的基本路径   2. easyloader.load('messager', function(){        // 加载指定的模块   3.     $.messager.alert('Title', 'load ok');   4. });  特性 名称 类型 说明 默认值 modules object 预定义的模块。
842 0
使用OpenApi弹性释放和设置云服务器ECS释放
云服务器ECS的一个重要特性就是按需创建资源。您可以在业务高峰期按需弹性的自定义规则进行资源创建,在完成业务计算的时候释放资源。本篇将提供几个Tips帮助您更加容易和自动化的完成云服务器的释放和弹性设置。
12076 0
飞天加速计划·教学提质 续费任务文章
此文章主要分享了关于使用云服务器ECS 的一些入门操作。
161 0
【精选】Nginx负载均衡学习笔记(一)实现HTTP负载均衡和TCP负载均衡(官方和OpenResty两种负载配置)
说明:很简单一个在HTTP模块中,而另外一个和HTTP 是并列的Stream模块(Nginx 1.9.0 支持) 一、两个模块的最简单配置如下 1、HTTP负载均衡: http { include mime.
1955 0
带你了解CDN缓存加速的工作原理.
从事关于网络安全防护的这份事业中,会遇见用户提出的各种问题。比如说家里的电脑和手机被监听怎么解决?网站打不开怎么解决?网站被DDoS攻击,服务器被拉入黑洞了,怎么快速解决?域名怎么防封?还有CDN缓存加速是什么?是通过什么样的原理运行的呢等等?今天墨者安全主要分享下CDN缓存加速的工作原理。
1198 0
+关注
天飞
一个运维老同志
1512
文章
0
问答
文章排行榜
最热
最新
相关电子书
更多
《2021云上架构与运维峰会演讲合集》
立即下载
《零基础CSS入门教程》
立即下载
《零基础HTML入门教程》
立即下载