简体   繁体   English

Apache ServerAlias无法重定向到正确的ServerName

[英]Apache ServerAlias not redirecting to correct ServerName

i'm try to setup multiple wordpress sites on my Amazon EC2 instance. 我尝试在我的Amazon EC2实例上设置多个wordpress网站。 Here's how my httpd.conf file looks like: 这是我的httpd.conf文件的样子:

<VirtualHost *:80>
   ServerName www.domain1.com
   ServerAlias domain1.com
   DocumentRoot /var/www/html/domain1
</VirtualHost>

<VirtualHost *:80>
   ServerName www.domain2.co
   ServerAlias domain2.co
   DocumentRoot /var/www/html/domain2
</VirtualHost>

So, when i entered domain1.com or www.domain1.com in the browser, it redirects correctly to the content i wanted and so does www.domain2.co . 因此,当我在浏览器中输入domain1.com或www.domain1.com时,它会正确地重定向到我想要的内容,而www.domain2.co也是如此。 However, when i entered domain2.co, it doesn't directs to the ServerName www.domain2.co but to the first VirtualHost settings www.domain1.com. 但是,当我输入domain2.co时,它不会定向到ServerName www.domain2.co,而是定向到第一个VirtualHost设置www.domain1.com。

Anything i'm missing out here? 我在这里想念什么吗?

Try this. 尝试这个。 Apache will default to the 1st virtual host if it doesn't find a virtualhost match which means your second VirtualHost is being ignored. 如果找不到与之匹配的Apache,它将默认为第一台虚拟主机,这意味着您的第二台VirtualHost被忽略。 We use www. 我们使用www。 as an alias and the domain as the server name. 作为别名,域名作为服务器名称。 See if this helps. 看看是否有帮助。

<VirtualHost *:80>
   ServerName domain1.com
   ServerAlias www.domain1.com
   DocumentRoot /var/www/html/domain1
</VirtualHost>

<VirtualHost *:80>
   ServerName domain2.com
   ServerAlias www.domain2.com
   DocumentRoot /var/www/html/domain2
</VirtualHost>

Figured it out guys, the browser caches previous data when domain2.co points to domain1.com. 搞清楚了,当domain2.co指向domain1.com时,浏览器会缓存以前的数据。 So even when i have set the virtualhost correctly for domain2.co, the browser will still load the previous cached data from domain1.com. 因此,即使我为domain2.co正确设置了虚拟主机,浏览器仍然会从domain1.com加载以前的缓存数据。

Solution will be to clear browser data. 解决方案将是清除浏览器数据。

Found out that another factor affecting this could be because of your ISP. 发现影响此的另一个因素可能是由于您的ISP。

Read more here: https://sg.godaddy.com/help/what-factors-affect-dns-propagation-time-1746 在此处阅读更多信息: https : //sg.godaddy.com/help/what-factors-affect-dns-propagation-time-1746

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM