简体   繁体   English

如何将域从 nginx 重定向到另一个在同一个 nginx 上工作的域?

[英]how redirect domain from nginx to another domain which is working on same nginx?

i have a server droplet in Digital ocean , two domains pointing out to that server A.com and B.com .我在数字海洋中有一个服务器小滴,两个域指向该服务器 A.com 和 B.com。 i want that when A.Com is call then nginx redirect it to B.com and server as B.com .我希望当 A.Com 被调用时,nginx 将它重定向到 B.com 和服务器作为 B.com 。 eg if user hit url from browser B.com then my site should be shown but if it Hit A.com then same site should be open but domain changes to B.com例如,如果用户从浏览器 B.com 中点击 url,则应显示我的站点,但如果它点击 A.com,则应打开同一站点,但域更改为 B.com

This is some example how to do it:这是一些如何做到这一点的例子:

server {
    listen 443 ssl http2;
    server_name  a.com;
    location / {
      return 301 $scheme://b.com$request_uri;
    }
}

Add this server block添加此服务器块

This is to redirect这是重定向

server {
   listen 80;
   server_name example.com; // your domain name
   location / {
          return 301 https://redirect-to.com; //Add your redirect url here
   }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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