如何使用 NGINX 重定向到不同的域? [英] How to redirect to a different domain using NGINX?

查看:48
本文介绍了如何使用 NGINX 重定向到不同的域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 NGINX 将 mydomain.com 和任何子域 *.mydomain.com 重定向到 www.adifferentdomain.com?

How can I redirect mydomain.com and any subdomain *.mydomain.com to www.adifferentdomain.com using NGINX?

推荐答案

server_name 支持使用 .mydomain.com 语法:

server_name supports suffix matches using .mydomain.com syntax:

server {
  server_name .mydomain.com;
  rewrite ^ http://www.adifferentdomain.com$request_uri? permanent;
}

或任何 0.9.1 或更高版本:

or on any version 0.9.1 or higher:

server {
  server_name .mydomain.com;
  return 301 http://www.adifferentdomain.com$request_uri;
}

这篇关于如何使用 NGINX 重定向到不同的域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆