nginx~对没有定义service_name的三级域名进行过滤,


在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页面。

相关内容

    暂无相关文章