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;
}
ZGC说:有什么能比不给牛吃草,还挤牛奶更快乐的事情呢?