LB | 192.168.200.120 |
web-pc | 192.168.200.121 |
web-phone | 192.168.200.122 |
web-pc配置
[root@nginx ~]# vim /etc/nginx/conf.d/test-01.conf
server {
listen 80;
server_name www.test-01.org;
root /code/test;
location / {
index index.html;
}
}
[root@nginx conf.d]# mkdir -p /code/test
[root@nginx conf.d]# echo "PC...web-01" >> /code/test/index.html
[root@nginx conf.d]# systemctl reload nginx.service
web-phone配置
[root@nginx ~]# vim /etc/nginx/conf.d/test-01.conf
server {
listen 80;
server_name www.test-01.org;
root /code/test;
location / {
index index.html;
}
}
[root@nginx ~]# mkdir -p /code/test/
[root@nginx ~]# echo "PHONE...web-02" >> /code/test/index.html
[root@nginx ~]# systemctl reload nginx.service
LB配置
[root@nginx ~]# vim /etc/nginx/conf.d/test-01.conf
upstream pc {
server 192.168.200.121:80;
}
upstream phone {
server 192.168.200.122:80;
}
server {
listen 80;
server_name www.test-01.org;
location / {
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
if ( $http_user_agent ~* "iphone|android|ipad" ) {
proxy_pass http://phone;
}
if ( $http_user_agent ~* "firefox|IE" ) {
return 302 'https://www.firefox.com.cn/';
}
proxy_pass http://pc;
}
}
测试