I was searching in nete how to create a virtual host and got confused - either simply at the end of httpd.conf you insert the VirtualHost container, or you need to stir up something with httpd-vhosts.conf. Please explain in detail how to create a virtual host, otherwise you really want to understand how it is created and the meaning of all directives. If anything, then I have Win XP and Apache 2.2.21.
1 answer
No matter where to add. If you add to httpd-vhosts.conf then do not forget just to connect it in the main httpd.conf file
Include conf/httpd-vhost.conf Then, in the httpd-vhost.conf file httpd-vhost.conf write:
#если хотите управлять различными доменами на различных IP и портахNameVirtualHost IP:Port #вставляете вместо предыдущего, если не хотите заморачиваться с адресамиNameVirtualHost *:80 Then the very first directive defines the virtual host by default, i.e. one that will work whenever a ServerName or ServerAlias is not found in any of the blocks of virtual hosts (they have the same format for all).
Now the blocks themselves:
#даст доступ к основному домену, если `C:\htdocs\mysite` - корень ваших проектов#вы получите доступ к любому из них используя `http://mysite.ru/www`, например<VirtualHost *:80> DocumentRoot "C:\htdocs\mysite" #путь к директории с файлами ServerName mysite.ru #основное имя вашего домена ErrorLog logs/default.error.log #лог ошибок HostNameLookups Off #распознавать имена подключающихся хостов или нет LogLevel debug #уровень логирования ServerAdmin mail@host.ru #е-мэйл адрес администратора #формат обычного лога (подробности в гугле) LogFormat "%h %l %u %t \"%r\" %>s %b" common #использование определенного выше формата для логирования CustomLog logs/default.access.log "common" #здесь описаны различные директивы для директории с которой мы работаем #(аналогично `httpd.conf`) <Directory "C:\htdocs\mysite"> deny from all allow from 127.0.0.1 Options -Indexes </Directory></VirtualHost>#следующий хост даст возможность пользоваться www.mysite.ru<VirtualHost *:80> DocumentRoot "C:\htdocs\mysite\www" #путь к директории с файлами ServerName www.mysite.ru #основное имя вашего домена ErrorLog logs/www.error.log #лог ошибок HostNameLookups Off #распознавать имена подключающихся хостов или нет LogLevel debug #уровень логирования ServerAdmin mail@host.ru #е-мэйл адрес администратора #формат обычного лога (подробности в гугле) LogFormat "%h %l %u %t \"%r\" %>s %b" common #использование определенного выше формата для логирования CustomLog logs/default.access.log "common" #здесь описаны различные директивы для директории с которой мы работаем #(аналогично `httpd.conf`) <Directory "C:\htdocs\mysite"> allow from all Options -Indexes </Directory></VirtualHost> - Thank you very much, of course, but please explain in more detail what you mean by saying "Then the very first directive defines the virtual host by default, that is, which will work whenever there are ServerName or ServerAlias matches in any of the virtual host blocks not found (they have the same format for all) "- by the very first directive you understand the first VirtualHost block or inside it - DocumentRoot, and how to understand" which will work whenever the ServerName or ServerAlias matches are not found in any of the virtual host blocks about "- i.e. I am talk_man am
- I can enter anything into the address bar, and if it does not match ServerName or ServerAlias in any of the virtual host blocks, then I will open this virtual host by default? - talk_man
- And can you please describe the directives of the directories in more detail? - talk_man
- 1. You have
ServerNameorServerAliasdirective in each<VirtualHost *.80>directive, when you enterwww.mysite.ruyou have the secondVirtualHostdirective, in which the server found a match in theServerNamedirective. Those. if you enter abracadabra into the address bar, then yes, you are right, the very firstVirtualHostdirective will work (but in order to enter that abracadabra, your DNS server must know it, or your DNS server should allow all types of abracadabra of your domain). 2 The description of all directives you can easily find on the Internet. - Dex - searched, but did not find - talk_man
|