nginx 动静分离

根据目录分离

upstream  stack_pools {
  server 172.25.254.134:80 weight=5;
}
upstream  dynamic_pools {
  server 172.25.254.135:80 weight=5;
}
server {
  listen       80;
  server_name  abc.test;
  location / {
    root   html;
    index  index.html index.htm;
    proxy_set_header Host $host;
    proxy_pass http://dynamic_pools;
  }
  # 图片目录跳转到图片服务器
  location /image/ {
    proxy_set_header Host $host;
    proxy_pass http://stack_pools;
  }
  location /dynamic/ {
    proxy_set_header Host $host;
    proxy_pass http://dynamic_pools;
  }
}

根据拓展名分离

upstream  stack_pools {
  server 172.25.254.134:80 weight=5;
}
upstream  dynamic_pools {
  server 172.25.254.135:80 weight=5;
}
server {
  listen       80;
  server_name  abc.test;
  location / {
    root   html;
    index  index.html index.htm;
    proxy_set_header Host $host:$server_port;
    proxy_pass http://dynamic_pools;
  }
  
  # 前端后缀文件跳转到前端服务器
  location ~ .*.(jpg|png|gif|css|js|swf|bmp)$ {
    gzip on;
    proxy_set_header Host $host:$server_port;
    proxy_pass http://stack_pools;
  }
}
}

你可能感兴趣的:(nginx 动静分离)