码迷,mamicode.com
首页 > 其他好文 > 详细

企业级应用服务动静分离

时间:2018-05-02 20:56:09      阅读:118      评论:0      收藏:0      [点我收藏+]

标签:负载均衡   动静分离   linux   

此处只贴出实现代码

技术分享图片

背景:通过Nginx实现7层动静分离,即通过Nginx反向代理配置规则实现让动态资源和静态资源及其他业务分别由不同的服务器解析。

测试机器准备工作
7层动静分离案例
负载均衡lb01

[root@lb01 ~]# cat /application/nginx/conf/proxy.conf 
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_connect_timeout 60;
proxy_send_timeout 60;
proxy_read_timeout 60;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
[root@lb01 ~]# cat /application/nginx/conf/nginx.conf
error_log  logs/error.log error;
worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    upstream static_pools {
            server 10.0.0.7:80 weight=1; #apache
    }
    upstream upload_pools {
            server 10.0.0.7:8080 weight=1; #apache
    }
    upstream default_pools {
            server 10.0.0.8:80 weight=1; #nginx
    }
  server {
        listen       80;
       server_name  blog.51cto.com;
       location / {
            proxy_pass http://default_pools;
            include proxy.conf;
       }
       location /static/ {
            proxy_pass http://static_pools;
            include proxy.conf;
       }
       location /upload/ {
            proxy_pass http://upload_pools;
            include proxy.conf;
       }
  }
}

Web02节点配置

[root@web02 ~]# cat /application/apache/htdocs/blog/static/index.html 
Static
[root@web02 ~]# cat /application/apache/htdocs/blog8080/upload/index.html 
Upload
[root@web02 extra]# pwd
/application/apache/conf/extra
[root@web02 extra]# awk ‘NR>16 && NR<24‘ httpd-vhosts.conf
<VirtualHost *:8080>
    ServerAdmin 278028843@qq.com
    DocumentRoot "/application/apache2.2.31/htdocs/blog8080"
    ServerName blog.51cto.com
    ErrorLog "logs/blog8080-error_log"
    CustomLog "logs/blog8080-access_log" common
</VirtualHost>

开启端口监听
vim /application/apache/conf/httpd.conf
技术分享图片

浏览器中测试:
http://blog.51cto.com/static/
http://blog.51cto.com/upload/
http://blog.51cto.com
技术分享图片
负载均衡01-日志
技术分享图片

企业级应用服务动静分离

标签:负载均衡   动静分离   linux   

原文地址:http://blog.51cto.com/jungiewolf/2111005

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!