企业级应用服务动静分离
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了企业级应用服务动静分离相关的知识,希望对你有一定的参考价值。
此处只贴出实现代码
背景:通过nginx实现7层动静分离,即通过Nginx反向代理配置规则实现让动态资源和静态资源及其他业务分别由不同的服务器解析。
测试机器准备工作
7层动静分离案例
负载均衡lb01
[[email protected] ~]# 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;
[[email protected] ~]# 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节点配置
[[email protected] ~]# cat /application/apache/htdocs/blog/static/index.html
Static
[[email protected] ~]# cat /application/apache/htdocs/blog8080/upload/index.html
Upload
[[email protected] extra]# pwd
/application/apache/conf/extra
[[email protected] extra]# awk ‘NR>16 && NR<24‘ httpd-vhosts.conf
<VirtualHost *:8080>
ServerAdmin [email protected]
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-日志
以上是关于企业级应用服务动静分离的主要内容,如果未能解决你的问题,请参考以下文章