简体   繁体   中英

Apache ServerAlias not redirecting to correct ServerName

i'm try to setup multiple wordpress sites on my Amazon EC2 instance. Here's how my httpd.conf file looks like:

<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 . 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.

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. We use 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. So even when i have set the virtualhost correctly for domain2.co, the browser will still load the previous cached data from domain1.com.

Solution will be to clear browser data.

Found out that another factor affecting this could be because of your ISP.

Read more here: https://sg.godaddy.com/help/what-factors-affect-dns-propagation-time-1746

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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