【发布时间】:2013-08-15 09:46:18
【问题描述】:
您好,我希望使用 Nginx 重定向到某个页面,例如: 当前域是 testing.example.com。我想要访问的页面是 testing.example.com/test 但我想要重定向的域是 t.example.com 所以:
t.example.com = testing.example.com/test
任何帮助谢谢!
【问题讨论】:
您好,我希望使用 Nginx 重定向到某个页面,例如: 当前域是 testing.example.com。我想要访问的页面是 testing.example.com/test 但我想要重定向的域是 t.example.com 所以:
t.example.com = testing.example.com/test
任何帮助谢谢!
【问题讨论】:
如果您只想重定向所有流量,请使用以下服务器块,如果您想连接 uri,则可以在 return 语句中添加 $request_uri。
$scheme 用于在重定向到的位置保留http 和https 协议,否则您可以在不使用$scheme 的情况下将其替换为任一协议
server {
server_name t.example.com;
location / {
return 301 $scheme://testing.example.com/test;
}
}
【讨论】:
添加您的t.example.com location { } 类似:
rewrite ^(.*) http://testing.example.com/test/$1 permanent;
或者只是简单的重定向
return 301 http://testing.example.com/test/;
【讨论】:
在您的 server 主机配置块中试试这个
location /test {
rewrite ^ $scheme://testing.example.com$request_uri permanent;
}
【讨论】: