场景一:
- 访问abc.realibox.com实际显示pandll.com站点内容,但地址栏仍然显示abc.pandll.com
- nginx检测abc未配置时,重定向到pandll.com,地址栏也显示pandll.com
场景二:
- 访问abc.pandll.com实际显示pandll.com/u/abc页面内容,地址栏仍然显示abc.pandll.com
- web检测abc未配置(即/u/abc不存在)时,跳转至pandll.com,地址栏也显示pandll.com
利用泛域名解析,将
*.pandll.com
解析pandll.com
站点相同IP地址Nginx配置如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31server {
listen 80;
server_name pandll.com;
location / {
try_files $uri /app.html;
}
}
# 场景一
server {
listen 80;
server_name *.pandll.com;
location / {
proxy_pass http://pandll.com;
}
}
# 场景二
server {
listen 80;
server_name *.pandll.com;
location / {
if ($http_host ~* "^(.*?)\.pandll\.com$") {
proxy_pass http://pandll.com/u/$1;
}
proxy_pass http://pandll.com;
}
}
参考资料:
nginx实现二级域名转发