2016-07-22 61 views

回答

0

試試這個:

server { 

    listen 443; 
    server_name www.example.com; 

    location ~* ^/(.+)\.txt$ { 
    return 301 http://www.anotherexample.com/api?pid=$1; 
    } 

} 

如果您pid有特定的格式(例如只位),然後用適當的方式代替(.+)

如果要在不重定向的情況下顯示內容,請將return 301替換爲proxy_pass

+0

我使用位置〜^ /([^ /。] *).txt $ { return 301 http://www.anotherexample.com/api?pid = $ 1; }但它說502錯誤,並找不到任何有用的error.log,任何想法? –

+0

@NingLv測試 - regexp在我的環境中正常工作。你添加了https params嗎?先用'listen 80;'嘗試'http://'。 – oakymax

+0

@NingLv也可以嘗試轉義反斜槓:'\ /'而不是'/'。這取決於nginx版本 – oakymax

0

最好的方法是使用return 301,它會將請求重定向到您要設置的網站,也許它會更好地製作一個return 301 $scheme://www.anotherexample.com/api?pid=$1;,這樣當您購買並安裝時,您的網址將被重定向爲HTTPS一個SSL

+0

我使用位置〜^ /([^ /。] *).txt $ { return 301 http://www.anotherexample.com/api?pid=$1; }但它說502錯誤,並找不到任何有用的error.log,任何想法? –