2016-09-19 51 views

回答

0

這很容易,我已經實現了這一點。您可以查看wittyfeed.com,它爲移動設備和桌面提供不同的文件。

這是可以做到的跟隨,

http { 
    .... 
    map $http_user_agent $ind { 
     "~*mobile" a.html; 
     default b.html; 
    } 


    server { 
     ... 
     index $ind; 
     ... 
     location/{ 
      try_files $uri $uri/ $ind; 
     } 
    } 
} 

上面的代碼運行作爲,它設置爲變量$ IND值,因爲如果a.html請求來自移動或以其他方式b.html。然後,相應地它會嘗試獲取文件。 :)

編輯w.r.t.評論如下,*沒有測試,

http { 
    ... 
    map $http_user_agent $proxy_addr { 
     "~*mobile" test-qa.firebaseapp.com/mobile; 
     default localhost:8080/test/jsp/index.jsp; 
    } 

    server { 
     ... 
     location /test { 
     proxy_pass $proxy_addr; 
     } 
    } 
} 
+0

thanx的反應,我的兩個文件是不同的服務器上,以便是有可能實現的same.if是那麼如何 –

+0

是有可能,你可以利用proxy_pass的,像,位置/ {proxy_pass server_address/$ ind; } – Satys

+0

目前我有這個 http { } 服務器{ listen \t \t 80; server_name dev.example.com; \t \t root/usr/local/tomcat7/webapps/ROOT; location/test { \t \t \t proxy_pass http://127.0.0.1:8080; \t \t \t proxy_read_timeout 900; \t \t} } 我有Java是爲了在8080端口上runnung的應用程序,我想,當用戶來自桌面那麼頁面的任期將從其端口的java 8080(本地主機:8080 /測試/ JSP /index.jsp),如果用戶來自移動網頁,那麼網頁將從這個網址提供https://test-qa.firebaseapp.com/mobile/ –

相關問題