I use MAMP ( Mac OS ). At the end of httpd.conf added the following:

 UseCanonicalName Off <VirtualHost *:80> ServerName loc ServerAlias *.loc VirtualDocumentRoot /Volumes/HDD/Sites/%1 </VirtualHost> 

But when trying to knock on mysite.loc (there is such a folder mysite ) says that the web page is not available. The vhost_alias module vhost_alias enabled. What am I doing wrong?

Update

Understood. It was necessary to register the address in /etc/hosts . However, I wanted to achieve the automatic addition of subdomains or even domains (without manipulating the hosts). Is it possible to achieve such a result with Apache manipulations? Or is it necessary to conjure with DNS ?

    1 answer 1

    It was necessary to register the address in /etc/hosts

    it needs an http client to know where to send requests.

    http server is not required.

    Experiment (substituting for the 127.0.0.1 ip- address of the machine where your http- server is running):

     $ curl -H 'host: blablabla.loc' http://127.0.0.1 

    funny examples:

     $ curl -I -H 'host: google.com' http://yandex.ru HTTP/1.1 406 Not acceptable $ curl -I -H 'host: yandex.ru' http://google.com HTTP/1.1 302 Found Location: http://www.google.com/ Cache-Control: private Content-Type: text/html; charset=UTF-8 X-Content-Type-Options: nosniff Date: Fri, 07 Aug 2015 19:08:58 GMT Server: sffe Content-Length: 219 X-XSS-Protection: 1; mode=block 
    • My http-server is on the local machine (127.0.0.1). There is a folder Sites / in which there are folders with sites (for example Sites / mysite /) that I want to access (respectively mysite.loc). However, simply adding a folder is not enough to access it. You must also enter the path (mysite.loc) in the hosts file (and I want to avoid this). As I understand it, in order not to edit the hosts file each time, it is necessary to configure the DNS server so that it automatically redirects me. But how to do it in Mac OS X is not clear. That's the question. Poke in the manual. - Fumo Sujimoshi pm
    • This is a completely different question. ask it, please, by clicking the " ask a question " button in the upper right corner of any page of the site. - aleksandr barakin 10:46 pm