1.准备站点目录
for i in {android,iphone,firefox,chrome,default} ;do mkdir /html/terminal/${i} && echo $i >/html/terminal/${i}/index.html ;done
2.准备配置文件
[root@RainGod conf.d]# cat android.conf chrome.conf default.conf firefox.conf iphone.conf
server{
listen 91;
root /html/terminal/android;
index index.html;
}
server{
listen 92;
root /html/terminal/chrome;
index index.html;
}
server{
listen 93;
root /html/terminal/default;
index index.html;
}
server{
listen 94;
root /html/terminal/firefox;
index index.html;
}
server{
listen 95;
root /html/terminal/iphone;
index index.html;
}
3.准备负载均衡 配置文件
[root@RainGod conf.d]# cat terminal.conf
upstream firefox {
server 127.0.0.1:94;
}
upstream chrome {
server 127.0.0.1:92;
}
upstream iphone {
server 127.0.0.1:95;
}
upstream android {
server 127.0.0.1:91;
}
upstream default {
server 127.0.0.1:93;
}
#//server根据判断来访问不同的页面
server {
listen 80;
server_name terminal.yangyijing.cn;
access_log /var/log/nginx/terminal_access.log main;
error_log /var/log/nginx/terminal_error.log warn;
#safari浏览器访问的效果
location / {
# if ($http_user_agent ~* "Safari"){
# proxy_pass http://dynamic_pools;
# }
#firefox浏览器访问效果
if ($http_user_agent ~* "Firefox"){
proxy_pass http://firefox;
}
#chrome浏览器访问效果
if ($http_user_agent ~* "Chrome"){
proxy_pass http://chrome;
}
#iphone手机访问效果
if ($http_user_agent ~* "iphone"){
proxy_pass http://iphone;
}
#android手机访问效果
if ($http_user_agent ~* "android"){
proxy_pass http://android;
}
#其他浏览器访问默认规则
proxy_pass http://default;
include proxy_params;
}
}
访问测试