如何禁用通过 IP 地址直接访问网站 [英] how to disable direct access to a web site by ip address

查看:27
本文介绍了如何禁用通过 IP 地址直接访问网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 VPS 上有一个网站.

I have a website on a VPS.

我遇到的问题是,当我输入服务器的 IP 时,它会链接到网站.
即使输入mail.domain.com,它也会做同样的事情.

The issue I am having is that when I enter the IP of the server, it links to the website.
Even when entering mail.domain.com, it does the same thing.

如何禁用它,以便访问者收到消息或被定向到域?

How do I disable that, so a visitor would get a message or be directed to the domain?

我尝试禁用 IP 并在 Cloudflare 上邮寄记录,但没有奏效.

I tried disabling the IP and mail a record on cloud flare but it didn't work.

我的设置是:

VPS on Linux Debian 
Nginx
no control panel just command line
Cloudflare
DNS setup with BIND

推荐答案

server {
    listen      80 default_server;
    listen      [::]:80 default_server;
    server_name "";
    return      444;
}

您需要指定default_server 参数,以便所有不可用的服务器请求都转到这个服务器块,这会引发444 错误.

You need to specify default_server parameter so that all non available server requests goes to this server block which throws 444 error.

444:连接关闭,没有响应

参考:https://httpstatuses.com/444

这篇关于如何禁用通过 IP 地址直接访问网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆