2016-02-19 51 views
1

我使用nginx作爲反向代理。如何在nginx的服務器塊中設置URL重定向,以便重定向到的URL是非http urlURL重定向到非http url,在nginx中

舉例來說,我有這種類型的網址:

http://example.com/user_uuid/a0d525aa-d755-11e5-b5d2-0a1d41d68578/14084561234/

我想從上面的重定向到非HTTP網址:

sms:14084561234?body:my photo is located at http://example.com/photos/a0d525aa-d755-11e5-b5d2-0a1d41d68578/

當這種非-http url打到瀏覽器,設備的本機短信應用程序打開,預填充短信的電話號碼爲1-408-456-1234,正文的文本出現在非http網址的?body之後。當然,這僅適用於移動設備。

這種事情可能嗎?如果是這樣,你能舉個例子嗎?請注意,在第一個URL中,uuid和數字根據一些以前的輸入動態生成


我已經知道了如何在我的web應用程序的代碼執行重定向,但是這不是問題。

回答

0

以下配置的工作原理:

server { 
    listen 99; 
    server_name test.so; 

    location /user_uuid { 
     rewrite /user_uuid/(.+)/([^/]+) "sms:$2?body:my photo is located at http://example.com/$1/" redirect; 
    } 

} 

示例輸出

curl -I -H "Host: test.so" http://localhost:99/user_uuid/uuid/phone/ 

HTTP/1.1 302 Moved Temporarily 
Server: nginx/1.7.11 
Date: Sat, 20 Feb 2016 00:45:22 GMT 
Content-Type: text/html 
Content-Length: 185 
Connection: keep-alive 
Location: sms:phone?body:my photo is located at http://example.com/uuid/ 
+0

感謝您的響應。我會測試它並回復你。 –