如何配置 Apache 拒绝(示例)http://192.168.1.1 并仅接受 http://www.example.com 等虚拟主机

发布于 2025-01-03 07:14:33 字数 539 浏览 4 评论 0原文

我试图寻找解决方案,但不知道如何构建查询以获得答案。

我想阻止任何人通过 IP url 探测我的服务器(例如 http://192.168.1.1 - 任何公共 IP 地址),同时允许正确的 URL 访问我的服务器(就像 http://www.example.com 一样)。

我觉得有四种方法:

  1. 在 httpd.conf 文件中创建一个“捕获 IP url”的虚拟主机条目。

  2. 创建一个 mod_rewrite 条目来重写也“捕获”它的 IP url。

  3. 创建一个能够检测 IP url 并丢弃这些连接请求的 IPTABLES 条目。

  4. 什么都不做,因为什么也做不了。

三者中哪一个(或推荐的替代方案)是处理它的最佳方法。我该怎么做呢?

谢谢。

I tried to search for a solution on this but didn't know how to frame the query to get my answer.

I want to block anyone from probing my server by IP urls (like http://192.168.1.1 -- any public IP address) while allowing properly URLs to my server (proper like http://www.example.com).

I feel there are four ways:

  1. Create a virtual host entry in httpd.conf file that "traps an IP url.

  2. Create a mod_rewrite entry to rewrite IP url that also "traps" it.

  3. Create an IPTABLES entry that is capable of detecting IP urls and dropping those connection requests.

  4. Do nothing because nothing can be done.

Which of the three (or recommend alternative) would be the best way to handle it. How woudl I do it?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

萌酱 2025-01-10 07:14:33

很简单。将以下内容设置为第一个虚拟主机:

NameVirtualHost *:80

<VirtualHost *:80>
<Directory "/path/to/root/site">
    AllowOverride All
    Options None
    Options Indexes FollowSymLinks Includes ExecCGI
    Order deny,allow
    Deny from none
    Allow from all
    php_admin_value open_basedir /path/to/root/site
</Directory>
    ServerAdmin admin@localhost
    DocumentRoot "/path/to/root/site"
    ServerName NX-DOMAIN
</VirtualHost>

在 /path/to/root/site 内部,只需创建一个简单的 .html 文件或显示“404 Not Found”的内容,甚至弹出 .htaccess 重定向或其他内容。

对于您的真实站点,将它们添加为第二、第三、第四等...虚拟主机:

<VirtualHost *:80>
<Directory "/path/to/real/site1/">
    AllowOverride All
    Options Indexes FollowSymLinks Includes ExecCGI
    Order allow,deny
    Allow from all
</Directory>
    ServerAdmin [email protected]
    DocumentRoot "/path/to/real/site1"
    ServerName www.domain.com
    ServerAlias domain.com
    php_admin_value open_basedir /path/to/real/site1
</VirtualHost>

这样,对您未托管的域的任何请求(如果有人将其域指向您的 IP 或有人访问原始 IP )将被转储到您的自定义错误页面。

希望这有帮助。

Very simple. Set the following as the VERY FIRST virtual host:

NameVirtualHost *:80

<VirtualHost *:80>
<Directory "/path/to/root/site">
    AllowOverride All
    Options None
    Options Indexes FollowSymLinks Includes ExecCGI
    Order deny,allow
    Deny from none
    Allow from all
    php_admin_value open_basedir /path/to/root/site
</Directory>
    ServerAdmin admin@localhost
    DocumentRoot "/path/to/root/site"
    ServerName NX-DOMAIN
</VirtualHost>

Inside of the /path/to/root/site, just make a simple .html file or something saying "404 Not Found" or even pop in a .htaccess redirect or something.

For your real sites, add these as the second, third, fourth, etc... virtual hosts:

<VirtualHost *:80>
<Directory "/path/to/real/site1/">
    AllowOverride All
    Options Indexes FollowSymLinks Includes ExecCGI
    Order allow,deny
    Allow from all
</Directory>
    ServerAdmin [email protected]
    DocumentRoot "/path/to/real/site1"
    ServerName www.domain.com
    ServerAlias domain.com
    php_admin_value open_basedir /path/to/real/site1
</VirtualHost>

That way, any request to a domain you don't host (if someone points their domain to your IP or someone visits the raw IP) will get dumped to your custom error page.

Hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文