nginx restricts access to domain names and prohibits IP access

Sometimes we hope that the system can only be accessed through a fixed domain name, prohibiting access to IP or maliciously bound domain names.

In the following nginx configuration, if the host variable is not the specified domain name, 403 will be returned.

 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 }

 

Guess you like

Origin www.cnblogs.com/fullee/p/12737858.html