例如,我想從https://www.example.com/ $ {pid} .txt重定向到http://www.anotherExample.com/api?pid= $ {pid} 如何在nginx中配置它? 感謝提前:)如何使用nginx中的參數重定向url
0
A
回答
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
最好的方法是使用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,任何想法? –
看到這個http://lethain.com/rewriting-parameterized-urls-with-nginx/ –
可能重複的[如何在NGINX中重定向url](http://stackoverflow.com/questions/10294481/how-to-redirect-a-url-in-nginx) –