在nginx配置過程中,你可能遇到過三級域名(泛域名)的問題,當你沒有定義它時,它會使用頂級域名的路由,你可以在配置中進行過濾
.
server {
listen 80;
server_name lind.company.cn *.lind.company.cn;
#匹配沒有定義過servicename的三級域名,讓它去404
if ($host ~* ^(.+)\.([^\.]+)\.([^\.]+)\.([^\.]+)$)
{
return 404;
}
location / {
root /home/web;
index index.html;
}
server {
listen 80;
server_name abc.lind.company.cn;
}
經過上面的配置之后,當你輸入abc.lind.company.cn它可以正常解析,而當你輸入xyz.lind.company.cn
時,它將返回到404頁面。