简体   繁体   中英

prevent user accessing site using server ip

My Apache Server IP address is 192.168.1.50 and the Domain Name is my.local . How do i restrict access to users using the IP address and not the server domain.

  • A user that uses the domain my.local can access the site, all files should also be accessible.
  • A user that uses the server IP 192.168.1.50 , should be redirected to the server domain, this being my.local . So if that user went to 192.168.1.50/somepage.php they would be redirected to my.local . If a user went to 192.168.1.50/images/someimage.jpg , they would be denied access.

How can this be achieved?

The most straightforward and flexible way is to create a separate virtual host with 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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