【发布时间】:2013-12-11 23:26:41
【问题描述】:
此配置按预期正常工作:
server {
listen 80;
server_name www.domain1.com domain1.com;
access_log /srv/www/domain1.com/logs/access.log;
location / {
root /srv/www/domain1.com/public_html;
index index.html index.htm;
}
}
server {
listen 80;
server_name domain2.com www.domain2.com;
access_log /srv/www/domain2.com/logs/access.log;
location / {
root /srv/www/domain2.com/public_html;
index index.html index.htm;
}
}
此配置在访问http://domain2.com 时显示来自 domain1 的内容:
server {
listen 80;
server_name *.domain1.com;
access_log /srv/www/domain1.com/logs/access.log;
location / {
root /srv/www/domain1.com/public_html;
index index.html index.htm;
}
}
server {
listen 80;
server_name *.domain2.com;
access_log /srv/www/domain2.com/logs/access.log;
location / {
root /srv/www/domain2.com/public_html;
index index.html index.htm;
}
}
我觉得我在这两种情况下都正确地关注了docs。
在示例 2 中使用通配符会导致意外行为的原因是什么?
【问题讨论】:
-
如果您希望您的网站显示为domain2.com,请删除星号。这意味着您需要拥有
server_name .domain1.com;和server_name .domain2.com;
标签: nginx wildcard server-name