0

I've tried searching for this scenario, but can't seem to find exactly this setup. I want to have something along the lines of the following:

I want to have two subdomains redirect to different https sites with different document roots. The ssl cert we have is domain level (*example.com). The following doesn't seem to work, in that when I put more than one virtualhost for each port, I get "This webpage is not available". Any suggestions?

NameVirtualHost *:80
NameVirtualHost *:443
<VirtualHost *:80>
  ServerName subdomain1.example.com
  RedirectPermanent / https://subdomain1.example.com
</VirtualHost>
<VirtualHost *:80>
  ServerName subdomain2.example.com
  RedirectPermanent / https://subdomain2.example.com
</VirtualHost>
<VirtualHost *:443>
  DocumentRoot /srv/www/subd1/
  ServerName subdomain1.example.com
  # more directives
</VirtualHost>
<VirtualHost *:443>
  DocumentRoot /srv/www/subd2/
  ServerName subdomain2.example.com
  # more directives
</VirtualHost>

We have the DNS directing both subdomain1.example.com and subdomain2.example.com to our server IP address.

Edit: Fixed an error in the example config (no ServerName directive) and added info regarding our DNS.

  • What do you get in your access logs? (which access logs are showing the expected activity?) – BE77Y Feb 23 '15 at 17:27
1

Your config sample should work (assuming that you have properly set the DNS entries corresponding to those virtual hosts to resolve to the server in question), but you don't seem to have included ServerName directives - try the following (assuming that this isn't just an error in construction of your example config):

NameVirtualHost *:80
NameVirtualHost *:443

<VirtualHost *:80>
  ServerName subdomain1.example.com
  RedirectPermanent / https://subdomain1.example.com
</VirtualHost>

<VirtualHost *:80>
  ServerName subdomain2.example.com
  RedirectPermanent / https://subdomain2.example.com
</VirtualHost>

<VirtualHost *:443>
  DocumentRoot /srv/www/subd1/
  ServerName subdomain1.example.com
  # more directives
</VirtualHost>

<VirtualHost *:443>
  DocumentRoot /srv/www/subd2/
  ServerName subdomain2.example.com
  # more directives
</VirtualHost>
  • I'm sorry, the missing ServerName directives were an error in my example config. I have updated the example given. I have also updated the prompt regarding the DNS. – wflynny Feb 23 '15 at 17:24
  • It turns out that I was missing some necessary directives in the second *:443 VirtualHost. Adding them fixed my problem. However, because you essentially confirmed that the overall structure of the vhosts.config file was correct, I will accept your answer so anyone searching this in the future can see how to set it up properly. – wflynny Feb 23 '15 at 20:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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