Home > Backend Development > PHP Tutorial > The setting on nginx prohibits accessing the server through IP and can only be accessed through domain name.

The setting on nginx prohibits accessing the server through IP and can only be accessed through domain name.

WBOY
Release: 2016-07-29 09:04:56
Original
1109 people have browsed it
为了避免别人把未备案的域名解析到自己的服务器ip而导致服务器被断网,需要在nginx上设置禁止通过ip访问服务器,只能通过域名访问。
最关键的一点是,在server的设置里面添加这么一行:
Listen 80 default;
后面的default参数表示这个是默认的虚拟主机。
例如:别人如果通过ip或者未知域名访问你的网站的时候,你希望禁止显示任何有效内容,可以给他返回500。具体如下:
Server {
       Listen 80 default;
       Server_name _;
       Return 500;
}
当然,按照上述设置,的确不能让别人通过ip访问服务器了,但是还应该开放一个或多个真实的希望被访问的域名配置,设置如下:
Server {
       Linten 80;
       Server_name www.941db.com; (以世海夺宝网为例)
………..
}
Copy after login

The above introduces the setting on nginx to prohibit access to the server through IP and can only be accessed through domain name, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template