nginx 将任何子域重写为特定 URL [英] nginx rewrite any sub-domain to specific URL
本文介绍了nginx 将任何子域重写为特定 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在 Nginx 中重定向以下场景的 url.
I want to redirect the url for the following scenario in Nginx.
我的域名*.xyz.com
如果用户从请求网址 ->abc.xyz.com
abc
不是常量名.
Xyz.com
是我的域,并且在 .xyz.com
重定向到 xyz.com/
之前的任何内容后台
Xyz.com
is my domain and anything before the .xyz.com
is redirecting to xyz.com/<abc>
in the backend
在后端请求转到abc.xyz.com
到 xyz.com/
但在浏览器中 URL 将是相同的.即 abc.xyz.com
But in the browser Url will be same.
i.e. abc.xyz.com
推荐答案
您可以对 server_name 使用正则表达式并将子域存储在命名捕获中.然后有一个变量根:
You could use a regular expression for your server_name and store the subdomain in a named capture. Then have a variable root:
server {
server_name ~^(?<subdomain>.+)\.xyz\.com$;
root /var/www/$subdomain;
}
这篇关于nginx 将任何子域重写为特定 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文