繁体   English   中英

Nginx从一个域重定向到另一个域?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM