nginx反向代理、根據瀏覽器分離訪問


環境根據http://www.cnblogs.com/zzzhfo/p/6032095.html配置

修改LB的/usr/local/nginx/conf/nginx.conf

upstream static_pools {
     server 192.168.119.130:80;
}   
upstream dynamic_pools {
     server 192.168.119.133:80;
}

    server {
        listen       80;
        server_name  www.test.com;
        location / {
            root   html;
            index  index.html index.htm;
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    if ($http_user_agent ~* "MSIE")      #MSIE IE瀏覽器
      {
        proxy_pass http://dynamic_pools;
      }
    if ($http_user_agent ~* "Firefox")    #Firefox火狐瀏覽器
      {
        proxy_pass http://static_pools;
      }
        }

在web01和web02上分別創建一個測試頁

web01

[root@web01 www]# echo Firefox > test.html

web02

[root@web02 www]# echo "IE" > test.html 

測試、分別使用Firefox和IE瀏覽器訪問

Firefox訪問(物理機沒有做hosts解析使用LB的IP訪問)

查看日志

web01

[root@web01 www]# tail -f /etc/httpd/logs/www.test.com.access_log
"192.168.119.1" - - [07/Oct/2016:22:35:07 +0800] "GET /favicon.ico HTTP/1.0" 404 290 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:49.0) Gecko/20100101 Firefox/49.0"
"192.168.119.1" - - [07/Oct/2016:22:36:17 +0800] "GET /test.html HTTP/1.0" 200 8 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:49.0) Gecko/20100101 Firefox/49.0"
"192.168.119.1" - - [07/Oct/2016:22:51:37 +0800] "GET /test.html HTTP/1.0" 200 8 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:49.0) Gecko/20100101 Firefox/49.0"
"192.168.119.1" - - [07/Oct/2016:22:56:05 +0800] "GET /test.html HTTP/1.0" 304 - "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:49.0) Gecko/20100101 Firefox/49.0"
"192.168.119.1" - - [07/Oct/2016:22:56:06 +0800] "GET /test.html HTTP/1.0" 304 - "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:49.0) Gecko/20100101 Firefox/49.0"
"192.168.119.1" - - [07/Oct/2016:22:56:06 +0800] "GET /test.html HTTP/1.0" 304 - "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:49.0) Gecko/20100101 Firefox/49.0"
"192.168.119.1" - - [07/Oct/2016:22:56:07 +0800] "GET /test.html HTTP/1.0" 304 - "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:49.0) Gecko/20100101 Firefox/49.0"
"192.168.119.1" - - [07/Oct/2016:22:56:08 +0800] "GET /test.html HTTP/1.0" 304 - "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:49.0) Gecko/20100101 Firefox/49.0"
"192.168.119.1" - - [07/Oct/2016:22:56:09 +0800] "GET /test.html HTTP/1.0" 304 - "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:49.0) Gecko/20100101 Firefox/49.0"
"192.168.119.1" - - [07/Oct/2016:22:56:09 +0800] "GET /test.html HTTP/1.0" 304 - "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:49.0) Gecko/20100101 Firefox/49.0"

web02

[root@web02 www]# tail -f /etc/httpd/logs/www.test.com.access_log
"192.168.119.136" - - [07/Oct/2016:22:46:28 +0800] "GET /test.html HTTP/1.0" 304 - "-" "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)"
"192.168.119.136" - - [07/Oct/2016:22:46:29 +0800] "GET /test.html HTTP/1.0" 304 - "-" "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)"
"192.168.119.136" - - [07/Oct/2016:22:46:29 +0800] "GET /test.html HTTP/1.0" 304 - "-" "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)"
"192.168.119.136" - - [07/Oct/2016:22:46:29 +0800] "GET /test.html HTTP/1.0" 304 - "-" "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)"
"192.168.119.136" - - [07/Oct/2016:22:46:30 +0800] "GET /test.html HTTP/1.0" 304 - "-" "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)"
"192.168.119.136" - - [07/Oct/2016:22:46:30 +0800] "GET /test.html HTTP/1.0" 304 - "-" "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)"
"192.168.119.136" - - [07/Oct/2016:22:46:30 +0800] "GET /test.html HTTP/1.0" 304 - "-" "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)"
"192.168.119.136" - - [07/Oct/2016:22:46:30 +0800] "GET /test.html HTTP/1.0" 304 - "-" "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)"
"192.168.119.136" - - [07/Oct/2016:22:56:40 +0800] "GET /test.html HTTP/1.0" 200 3 "-" "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)"
"192.168.119.136" - - [07/Oct/2016:22:56:41 +0800] "GET /test.html HTTP/1.0" 304 - "-" "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)"

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM