简体   繁体   中英

How to restrict apache virtual hosts?

I have one site enabled, for example foobar.com .
But when I open IP address 127.0.0.1 - it's opens my foobar.com .
Whatever maps to 127.0.0.1 in /etc/hosts I open - foobar.com is opened.

How can I configure virtualhost/apache to only allow access from foobar.com ?

Apache 2.4, Ubuntu 13.10

Apache always uses the first VirtualHost as the "default" host. That is, whenever it can't map the requested hostname ( 127.0.0.1 in your case) to a specific VirtualHost, it will use that default one.

Just define another VirtualHost before the foobar.com one. If you have both in the same configuration, configure the default one first. If you have separate config files, name the "default" one so, that it gets loaded before the foobar.com one. Many Linux distributions use a name like 00-default.conf for the default VHost.

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