Nginx动静分离

//默认动态,静态直接找设置的static,上传找upload
upstream static_pools {
server 10.0.0.9:80 weight=1;
}
upstream upload_pools {
server 10.0.0.10:80 weight=1;
}
upstream default_pools {
server 10.0.0.9:8080 weight=1;
}

server {
    listen       80;
    server_name  www.xuliangwei.com;

url: https://www.xuliangwei.com/

location / { 
    proxy_pass http://default_pools;
    include proxy.conf;
}

url: https://www.xuliangwei.com/static/

location /static/ {
    proxy_pass http://static_pools;
    include proxy.conf;
}

url: https://www.xuliangwei.com/upload/

location /upload/ {
    proxy_pass http://upload_pools;
    include proxy.conf;
}

}

//方案2:以if语句实现。
if ($request_uri ~* "^/static/(.)$")
{
proxy_pass http://static_pools/$1;
}
if ($request_uri ~
"^/upload/(.*)$")
{
proxy_pass http://upload_pools/$1;
}
location / {
proxy_pass http://default_pools;
include proxy.conf;
}

posted @ 2019-07-26 20:19  atomFix  阅读(162)  评论(0编辑  收藏  举报