Nginx禁止使用ip访问,只允许使用域名访问

Nginx虚拟主机配置,vhosts下面有很多域名的配置:

[root@external-lb01 vhosts]# pwd
/data/nginx/conf/vhosts

[root@external-lb01 vhosts]# ls
443-bpm.veredholdings.com.conf 80-www.bigtreefinance.com.conf fax.bigtreefinance.com.conf
443-www.bigtreefinance.com.conf 80-www.bigtreefinance.com.conf.bak20180307 mobi.bigtreefinance.com.conf
443-www.bigtreefinance.com.conf.bak bpm.bigtreefinance.com.conf www.bigtreefinance.com.conf.bak
443-www.bigtreefinance.com.conf.bak20180307 demo.bigtreefinance.com.conf
80-bpm.veredholdings.com.conf

 

如果有禁止ip访问,只允许域名访问,只需要配置如下即可:

[root@external-lb01 vhosts]# cat deny.ip.conf

server {
     listen 80 default;
     server_name _;
     return 500;
}


[root@external-lb01 vhosts]# /data/nginx/sbin/nginx -t
nginx: the configuration file /data/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /data/nginx/conf/nginx.conf test is successful

[root@external-lb01 vhosts]# /data/nginx/sbin/nginx -s reload

你可能感兴趣的:(Nginx禁止使用ip访问,只允许使用域名访问)