# 未按安装指南操作时，网站可通过IP地址访问

**URL:** <https://meta.discourse.org/t/site-is-accessible-on-the-ip-address-when-not-following-th-install-guide/156214>\
**Category:** Feature\
**Created:** [2020年六月29日 07:25 UTC](https://meta.discourse.org/t/site-is-accessible-on-the-ip-address-when-not-following-th-install-guide/156214 "2020-06-29T07:25:59Z")\
**Posts on this page:** 1\
**Showing post:** 12

<div class="post-metadata">

**Author:** ![elijah](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/elijah/32/104055_2.png) [@elijah](https://meta.discourse.org/u/elijah)\
**Post date:** [2020年六月30日 05:06 UTC](https://meta.discourse.org/t/site-is-accessible-on-the-ip-address-when-not-following-th-install-guide/156214/12 "2020-06-30T05:06:00Z")

</div>

> [@markersocial](#):
>
> 其中 1.1.1.1 是服务器的公网 IP 地址。可能有一种更优雅的方式来包含 IP 地址，而不是硬编码。我尝试了几种方法，但都没能成功。

我使用以下配置，将直接通过 IP 访问的机器人重定向到特殊页面：

```plaintext
server {
        listen 80;
        # listen [::]:80;

        server_name ~^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+;

        root /var/www/ip-address;
        default_type text/plain;
        index nothing.doing;
        location / {
                try_files $uri /nothing.doing;
        }
}

```

但我和其他人一样，也无法在我的私有论坛中通过 IP 直接访问。我总会收到重定向。而且我的论坛没有任何特殊配置，没有使用 Cloudflare，并且[实际上运行在一台每月 0 美元的虚拟服务器上](https://meta.discourse.org/t/self-hosting-for-free-with-oracle-cloud/139184/)，没有任何额外功能。

---

_[View the full topic](https://meta.discourse.org/t/site-is-accessible-on-the-ip-address-when-not-following-th-install-guide/156214)._
