您的位置:首页 > 运维架构 > Nginx

nginx动静分离

2016-05-12 16:56 585 查看
1.最好的情况是在业务上做动静分离,如果业务没有做此功能,nginx也可以实现

2.方式1:利用URL匹配

访问地址:http://www.vijay.com/status



3.方式2:利用扩展名匹配



3.方式3:利用rewrite中的if(此方式还可以用于判断浏览器,如判断浏览器是IE6,则转发提示页面,提示浏览器版本低,请升级)



4.根据user客户端类型(win,mac,ios,安卓)进行请求分配:(关键参数:proxy_set_header http_user_agent $http_user_agent;)



#样式
location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css|font|ttf)$ {
if ($http_user_agent ~* (mobile|nokia|iphone|ipad|android|samsung|htc|blackberry)){
root /usr/local/nginx/html/proxy_mobile;
}
root /usr/local/nginx/html/dist;
}

#后台数据接口
location ~* /(ipagent)/ {
proxy_pass http://backend; }

#首页
location  / {
#root   /usr/local/nginx/html/;
#index  index.html index.htm index.html;
if ($http_user_agent ~* (mobile|nokia|iphone|ipad|android|samsung|htc|blackberry)){

#try_files $uri $uri/proxy_mobile/ /index.html;
#index  index.html index.htm;
root /usr/local/nginx/html/proxy_mobile;
#index  index.html index.htm;
}

try_files $uri $uri/dist /index.html;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: