简体   繁体   中英

Virtual Host Subsites apache 2.4

I'm setting up 2 wordpress sites. The scenario is that there are two Wordpress installations, in the folder var/www/domain/us and var/www/domain/eu. The domain.com/us should be the default option when you access the site from domain.com Users access the site through: domain.com/us or domain.com/eu

Right now the setup for virtual host is: (I don't have a real domain name attached, so its only IP address so far)

<VirtualHost *:80>
 ServerName [IP-address]
 ServerAlias [IP-address]
 DocumentRoot /var/www/domain/us
 ErrorLog /var/www/html/domain.com/logs/error.log
 CustomLog /var/www/html/domain.com/logs/access.log combined
</VirtualHost>


<VirtualHost *:80>
 ServerName [IP-address]/us
 DocumentRoot /var/www/domain/us
 ServerAlias [IP-address]
 ErrorLog /var/www/html/domain.com/logs/error.log
 CustomLog /var/www/html/domain.com/logs/access.log combined
</VirtualHost>

<VirtualHost *:80>
 ServerName [IP-address]/eu
 DocumentRoot /var/www/domain/eu
 ServerAlias [IP-address]
 ErrorLog /var/www/html/domain.com/logs/error.log
 CustomLog /var/www/html/domain.com/logs/access.log combined
</VirtualHost>

I can access the IP address with the primary virtual host, but the last two IP/us and IP/eu is giving Page not found.

What am I doing wrong?

ServerName interprets the path as part of the hostname. Server name can contain the request scheme, hostname and port, but not the path. Therefore only the first virtual host is valid.

Since you are on Apache 2.4, you can use conditional directives to solve the problem. In the first virtual host add the following, and then remove the other two:

<VirtualHost *:80>
 ServerName [IP-address]
 ServerAlias [IP-address]
 <If "%{REQUEST_URI} =~ m#^/eu.*$#">
   DocumentRoot /var/www/domain/eu
 </If>
 <Else>
   DocumentRoot /var/www/domain/us
 </Else>
 ErrorLog /var/www/html/domain.com/logs/error.log
 CustomLog /var/www/html/domain.com/logs/access.log combined
</VirtualHost>

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