[英]Nginx redirect from one domain to another?
我正在將同一應用程序遷移到另一個域。
對於舊域,我將路由設置為:
http://app.example.com/app/users/sign_in?query=hello
我希望將其重定向到另一個域,從而省略了app
部分,因為:
http://app.newexample.com/users/sign_in?query=hello
我嘗試了:
server {
...
location /app {
rewrite ^$scheme://app.sparkon.com/app(/.*)$ $1 last;
}
...
}
我不工作 如何實現呢?
我大約一年前有這個問題,花了很長時間尋找解決方案。 我發現並使用了這個:
server {
listen 80;
server_name example.com app.example.com;
rewrite ^/app(.*)$ http://app.newexample.com$1 permanent;
}
server {
listen 80;
server_name app.newexample.com;
# config for primary domain here
}
從這個鏈接 。 歸功於他們。
不要將方案放在重寫模式中:
server {
server_name app.example.com;
location /app/ {
rewrite ^/app/(.*)$ http://app.newexample.com/$1;
}
}
BRG。
我喜歡這種方法,因為它不需要使用重寫,我讀過的一件事很好避免了太多,因為它需要nginx引擎進行更多處理。
location ~ /app/(.*) {
return 301 $scheme://app.sparkon.com/$1;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.