如何在Nginx配置中排除特定的子域server_name [英] How to exclude specific subdomains server_name in nginx configuration
本文介绍了如何在Nginx配置中排除特定的子域server_name的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在server_name
中使用通配符.我想将example.com
(配置为* .example.com)的所有子域重定向到foo.com
,除了xyz.example.com
I'm using wildcard in server_name
. I want to redirect all subdomains of example.com
(configured as *.example.com) to foo.com
except xyz.example.com
我的配置如下
server {
listen 80;
server_name *.example.com;
location / {
proxy_pass http://$1.foo.com;
}
}
我不想更改对xyz.example.com
推荐答案
您至少需要两个服务器块,并且nginx
将选择更具体的服务器块来处理请求.有关详细信息,请参见本文档.
You need at least two server blocks, and nginx
will select the more specific server block to handle the request. See this document for details.
对于xyz.example.com
,您将需要一个服务器块,例如:
You will need a server block for xyz.example.com
such as:
server {
listen 80;
server_name xyz.example.com;
location / {
proxy_pass http://$1.foo.com;
}
}
然后是default_server
或通配符服务器,例如:
Then either a default_server
or a wild card server, such as:
server {
listen 80;
server_name *.example.com;
return http://foo.com/;
}
或者:
server {
listen 80 default_server;
return http://foo.com/;
}
这篇关于如何在Nginx配置中排除特定的子域server_name的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文