简体   繁体   中英

limit apache virtualhost to one domain?

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?

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

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