nginx限制访问域名,禁止IP访问

有些时候我们希望系统只能通过固定的域名访问,禁止IP或者恶意绑定的域名访问。

下面的nginx配置,假入host变量不是指定的域名,将返回403。

 1 server {
 2     listen 80;
 3     server_name newcoina.xgyxserv.com;
 4 
 5     if ($host != 'newcoina.xgyxserv.com'){
 6         return 403;
 7     }
 8 
 9     location / {
10         root /www;
11     }
12 }

猜你喜欢

转载自www.cnblogs.com/fullee/p/12737858.html
今日推荐