在不重新启动服务器的情况下在Apache上添加新的VirtualHosts?
-
12-10-2019 - |
题
我的Apache工作正常,虚拟主机按预期工作。我的操作系统是Windows 7。
但是,我遇到了一个问题,我正在尝试找到答案,而Google的收益并不多 - 对于Windows来说,仅适用于Linux(在这种情况下这并不适用)。
如何添加新的VirtualHost,而不会不断重新启动服务器?
(Apache版本2.2是我当前正在运行的)
我将新的主机添加到主机文件和文件中,就像这样:
<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>
有没有人使用类似的解决方案,如果是,您的建议是什么?
解决方案
您可以在不重新启动服务器的情况下重新启动Apache。我的Mac上有一个Apple脚本,可以为我重新启动Apache,因此一键单击和一秒钟的Quater可以加载新的Apache配置。这是Apple脚本,可以轻松移植到Python(用于您的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
其他提示
您可能能够使用一个块配置所有vhost 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>
不隶属于 StackOverflow