問題
頂級(jí)域名 a.com
和子域名 b.a.com
解析到同一個(gè)服務(wù)器IP浇辜,但被 Nginx 同一化處理榄笙。我的預(yù)期是 Nginx 分別代理兩個(gè)域名。
Nginx 當(dāng)前關(guān)鍵配置:
server {
listen 80;
server_name a.com;
location / {
proxy_pass http://127.0.0.1:8080/APIs/;
}
}
解決
server {
listen 80;
server_name a.com www.a.com;
location / {
proxy_pass http://127.0.0.1:8080/Hello/;
}
}
server {
listen 80;
server_name b.a.com;
location / {
proxy_pass http://127.0.0.1:8080/APIs/;
}
}
拓展
Nginx 對(duì) server_name
的匹配順序:
- 準(zhǔn)確字符串
server {
listen 80;
server_name a.com www.a.com;
}
- 以通配符開始的字符串
server {
listen 80;
server_name *.a.com;
}
- 以通配符結(jié)束的字符串
server {
listen 80;
server_name www.*;
}
- 正則表達(dá)式
server {
listen 80;
server_name ~^(?.+)\.a\.com$;
}