I have a domain example.com with two subdomains: website.example.com and cloud.example.com. I set an A-Record for both of them to my server's IP address.

my server is a VPS with centos7 and has two directories below /var/www/html/ for each of the domains:

  • /var/www/html/website.example.com/ contains all wordpress files
  • /var/www/html/cloud/ contains all files for ownCloud.

I enhanced my httpd.conf to contain:

Listen 80
Listen 81

# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80

<VirtualHost *:80>
DocumentRoot /var/www/html/website.example.com
ServerName www.website.example.com

NameVirtualHost *:81
<VirtualHost *:81>
DocumentRoot /var/www/html/cloud
ServerName www.cloud.example.com

Now, when I restart httpd and run wget i get the following responses:

  • my.vps.ip.address -> response from wordpress site
  • my.vps.ip.address:80 -> response from wordpress site
  • my.vps.ip.address:81 -> response from cloud site
  • website.example.com -> response from wordpress site
  • cloud.example.com -> response from wordpress site.

This results to the browser experience -> When i enter website.example.com in my browser I get on my wordpress site. But when I enter cloud.example.com I also get on my wordpress site instead of the owncloud site.

What am I missing?


You've set your ServerName to www.cloud.example.com, but try to access it with cloud.example.com. Also you forgot the port 81.

Either set it to cloud.example.com or add an ServerAlias cloud.example.com.

You don't need to set the cloud.example.com on a different port. Apache is perfectly capable of handling different VirtualHosts on the same port. Just leave it on port 80.

It should look like this:

Listen 80
# Listen 81
# Just stay on port 80, don't make it more complicated for the clients

# Listen for virtual host requests on all IP addresses
# NameVirtualHost *:80
# This is not needed anymore with Apache 2.4

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

<VirtualHost *:80>
DocumentRoot /var/www/html/cloud
ServerName cloud.example.com
  • I adapted my httpd conf according to your comment. now the wget for cloud.example.com does return the correct response. Only problem is that I cannot get the correct response using chrome. cloud.example.com in chrome still leads to website.example.com. Entering the IP in chrome leads to website.example.com – talbx Feb 15 at 8:22
  • Did you restart apache? Did you clear your browser cache? If you access apache with a hostname that is not configured (like you do when you use the IP) apache uses the first listed VirtualHost. See my answer here for details. – Gerald Schneider Feb 15 at 8:32
  • I added an example configuration to the answer – Gerald Schneider Feb 15 at 8:35
  • I now use the full configuration provided by you. still I can only access the website.example.com , while cloud.example.com gets redirected. I assume, the problem lays in my DNS configuration. I setup the two subdomains in my domain provider, though my server is hosted somewhere else and probably the linking between the host /server names isnt working out, but actually i have no clue how to fix that. As of now both have the same A-Record -> Ip address of the vps. Does my vps need some dns configuration or something? – talbx Feb 15 at 8:44
  • Redirection does not happen via DNS. If you get an actual redirect (the URL in your browser changes from cloud to website) you have something else configured in your Apache that you haven't shown yet. – Gerald Schneider Feb 15 at 8:53

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.