限制apache虚拟主机到一个域?

发布于 2024-12-23 07:58:50 字数 272 浏览 3 评论 0原文

我有虚拟主机的配置:

<VirtualHost xx.xx.xx.xxx>
  ServerName mydomain.com
  ServerAlias *
  ...
</VirtualHost>

在 mydomain.com 上一切正常。但问题是有人将他的域链接到我的应用程序 IP,我想避免这种情况。是否可以将虚拟主机限制为仅一个域“mydomain.com” - 因此如果有人将他的域指向我的IP - 虚拟主机将不会处理此请求?

I have configuration of virtualhost:

<VirtualHost xx.xx.xx.xxx>
  ServerName mydomain.com
  ServerAlias *
  ...
</VirtualHost>

everything works fine on mydomain.com. But the problem is that someone linked his domain to my application ip and I want to avoid this. Is it possible to limit virtualhost to only one domain "mydomain.com" - so if somebody will point his domain to my ip - virtualhost will not process this request?

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

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

发布评论

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

评论(1

随波逐流 2024-12-30 07:58:50

无法阻止它应答该 IP 地址上的 HTTP 请求。我认为,如果您要使用基于名称的托管,然后使用 ServerName 1.2.3.4 创建一个虚拟主机,那么它将匹配对 IP 地址的请求,并且您可以添加一些特殊的那里的行为(返回错误代码、重定向到指定站点等)。

如果您只是想确保人们不会为 IP 地址添加书签并始终在浏览器中看到 mydomain.com,请查看 http://httpd.apache.org/docs/2.0/misc/rewriteguide.html

There's no way to prevent it from answering HTTP requests on that IP address. I think that if you were to use name based hosting and then create a vhost with ServerName 1.2.3.4 then it'd be matched for requests to the IP address and you'd be able to add some special behaviour there (return an error code, redirect to the named site, etc).

If you just want to make sure that people don't bookmark the IP address and always see mydomain.com in the browser then have a look at the section on Canonical Hostnames in http://httpd.apache.org/docs/2.0/misc/rewriteguide.html

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