Add new virtual hosts on Apache without restarting the server?

My Apache is working fine, virtual hosts are working as expected. My operating system is Windows 7.

However, I have one problem that I am trying to find an answer to, and Google has not yielded much - for Windows in any case, only for Linux (which is not applicable in this case).

How to add new virtual hosts without restarting the server?

(Apache 2.2 version is what I am doing now)

I add new hosts to the host file and files in vhosts, for example:

<VirtualHost *:80> ServerName host1.tld ServerAlias www.host1.tld DocumentRoot /www/vhosts/host1.tld ErrorLog /www/Apache22/logs/error.log <Directory "/www/vhosts/host1.tld"> Options All AllowOverride All order allow,deny allow from all </Directory> 

 <VirtualHost *:80> ServerName mywebsite.com ServerAlias www.mywebsite.com DocumentRoot /www/vhosts/mywebsite.com ErrorLog /www/Apache22/logs/error.log <Directory "/www/vhosts/mywebsite.com"> Options All AllowOverride All order allow,deny allow from all </Directory> 

Has anyone been in a similar decision, and if so, what is your advice?

+4
source share
2 answers

You can restart apache without restarting the server. I have an apple script on my mac that restarts apache for me, so that with a single click and a quarter of a second a new apache configuration can be loaded. Here is an apple script that can be easily ported to Python (for your use of Windows):

 set stopString to do shell script "sudo /usr/local/apache2/bin/apachectl stop" with administrator privileges and password set startString to do shell script "sudo /usr/local/apache2/bin/apachectl start" with administrator privileges and password if startString as string = "" then "Apache started correctly" else stopString & " , " & startString end if 
0
source

You can configure all vhosts in one block using VirtualDocumentRoot

 <VirtualHost *:80> UseCanonicalName Off VirtualDocumentRoot /www/vhosts/%0 ErrorLog /www/Apache22/logs/error.log <Directory "/www/vhosts"> Options All AllowOverride All order allow,deny allow from all </Directory> 
+3
source

Source: https://habr.com/ru/post/1335887/


All Articles