简体   繁体   English

防止用户使用服务器ip访问站点

[英]prevent user accessing site using server ip

My Apache Server IP address is 192.168.1.50 and the Domain Name is my.local . 我的Apache服务器IP地址为192.168.1.50 ,域名为my.local How do i restrict access to users using the IP address and not the server domain. 我如何使用IP地址而不是服务器域限制对用户的访问。

  • A user that uses the domain my.local can access the site, all files should also be accessible. 使用域my.local用户可以访问该站点, 所有文件也应该可以访问。
  • A user that uses the server IP 192.168.1.50 , should be redirected to the server domain, this being my.local . 使用服务器IP 192.168.1.50用户应重定向到服务器域,即my.local So if that user went to 192.168.1.50/somepage.php they would be redirected to my.local . 因此,如果该用户转到192.168.1.50/somepage.php他们将被重定向到my.local If a user went to 192.168.1.50/images/someimage.jpg , they would be denied access. 如果用户转到192.168.1.50/images/someimage.jpg ,则将拒绝他们访问。

How can this be achieved? 如何做到这一点?

The most straightforward and flexible way is to create a separate virtual host with ServerName 192.168.1.50 . 最直接,最灵活的方法是使用ServerName 192.168.1.50创建单独的虚拟主机。 Just don't create it as the first virtualhost for any port, as it would become the default. 只是不要将其创建为任何端口的第一个虚拟主机,因为它将成为默认端口。

You can then use all the basic directives to redirect or perform access control, all in the context of 192.168.1.50. 然后,您可以在192.168.1.50的上下文中使用所有基本指令来重定向或执行访问控制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM