HELP! I just setup a virtual host for two sites that have a lot of traffic and I think I just messed something up! Here is the end of my httpd.conf:
救命!我刚为两个拥有大量流量的网站设置了虚拟主机,我想我只是搞砸了!这是我的httpd.conf的结尾:
NameVirtualHost *
<VirtualHost *>
ServerName www.mydomain.com
DocumentRoot /var/www/html
</VirtualHost>
<VirtualHost *>
ServerName www.mydomain2.com
DocumentRoot /var/www/downloadr
</VirtualHost>
<VirtualHost *>
ServerName mydomain2.com
DocumentRoot /var/www/downloadr
</VirtualHost>
I added the last virtual host to solve the problem of mydomain2.com going to wwww.mydomain.com. HOWEVER, what has happened now is that www.mydomain2.com goes to www.mydomain.com.
我添加了最后一个虚拟主机来解决mydomain2.com转到wwww.mydomain.com的问题。但是,现在发生的事情是www.mydomain2.com访问www.mydomain.com。
Please help!!!
Thanks all
UPDATE
STUPIDITY beyond words - managed to copy one site to two directories and hence the 2 domains pointing to the same place!! OMG this will not happen again. Double check and recheck and recheck and recheck and recheck and recheck........
超越单词的愚蠢 - 设法将一个站点复制到两个目录,因此2个域指向同一个地方! OMG这不会再发生了。仔细检查并重新检查并重新检查并重新检查并重新检查并重新检查........
Btw, why would someone neg rep me for this?
顺便问一下,为什么有人会为此代表我?
2 个解决方案
#1
Instead of adding the third virtual host, add
添加,而不是添加第三个虚拟主机
ServerAlias mydomain2.com
to the second one. So your entire configuration would be basically this:
到第二个。所以你的整个配置基本上是这样的:
NameVirtualHost *
<VirtualHost *>
ServerName www.mydomain.com
DocumentRoot /var/www/html
</VirtualHost>
<VirtualHost *>
ServerName www.mydomain2.com
ServerAlias mydomain2.com
DocumentRoot /var/www/downloadr
</VirtualHost>
If you want requests for mydomain.com
to actually be redirected to www.mydomain.com
, so that the user sees the URL change in his/her browser, that can be done with mod_rewrite
(but that's the subject of another question, search for it if you like)
如果您希望mydomain.com的请求实际上被重定向到www.mydomain.com,那么用户可以在他/她的浏览器中看到URL更改,这可以通过mod_rewrite完成(但这是另一个问题的主题,搜索它,如果你喜欢)
#2
I was also having problems with this it turns out that for ServerName
Apache did not like the www prepended. So it should look like this:
我也遇到了问题,事实证明,对于ServerName,Apache并不喜欢www prepended。所以看起来应该是这样的:
<VirtualHost *>
ServerName mydomain2.com
ServerAlias www.mydomain2.com *.mydomain.com
DocumentRoot "c:/wamp/www" #WAMP INSTALL
</VirtualHost>
#1
Instead of adding the third virtual host, add
添加,而不是添加第三个虚拟主机
ServerAlias mydomain2.com
to the second one. So your entire configuration would be basically this:
到第二个。所以你的整个配置基本上是这样的:
NameVirtualHost *
<VirtualHost *>
ServerName www.mydomain.com
DocumentRoot /var/www/html
</VirtualHost>
<VirtualHost *>
ServerName www.mydomain2.com
ServerAlias mydomain2.com
DocumentRoot /var/www/downloadr
</VirtualHost>
If you want requests for mydomain.com
to actually be redirected to www.mydomain.com
, so that the user sees the URL change in his/her browser, that can be done with mod_rewrite
(but that's the subject of another question, search for it if you like)
如果您希望mydomain.com的请求实际上被重定向到www.mydomain.com,那么用户可以在他/她的浏览器中看到URL更改,这可以通过mod_rewrite完成(但这是另一个问题的主题,搜索它,如果你喜欢)
#2
I was also having problems with this it turns out that for ServerName
Apache did not like the www prepended. So it should look like this:
我也遇到了问题,事实证明,对于ServerName,Apache并不喜欢www prepended。所以看起来应该是这样的:
<VirtualHost *>
ServerName mydomain2.com
ServerAlias www.mydomain2.com *.mydomain.com
DocumentRoot "c:/wamp/www" #WAMP INSTALL
</VirtualHost>