How does Nginx not allow access via IP?

WBOY
Release: 2023-05-19 11:43:06
forward
2137 people have browsed it

不允许通过IP访问

server {
 listen  80 default;
 server_name _;

 return  404;
}
Copy after login

可能有一些未备案的域名或者你不希望的域名将服务器地址指向了你的服务器,这时候就会对你的站点造成一定的影响,需要禁止IP或未配置的域名访问,我们利用上边所说的default规则,将默认流量都转到404去

上边这个方法比较粗暴,当然你也可以配置下所有未配置的地址访问时直接301重定向到你的网站去,也能为你的网站带来一定的流量

server {
 rewrite ^/(.*)$ https://ops-coffee.cn/$1 permanent;
}
Copy after login

The above is the detailed content of How does Nginx not allow access via IP?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!