0

I want to have two sites that use the same domain name and also shares same folder and what separates them is a prefix in the URL.

For example:

  1. mywebsite.domain.com => /var/www/site1
  2. mywebsite1.domain.com => /var/www/site1

How can I achieve this in apache2 on port 443? i just want to configure it in 000-default.conf file instead of creating multipe sites.conf file.

2
  • Use ServerAlias directive.
    – pa4080
    Oct 8, 2020 at 7:18
  • Thanks for your time, i have added ServerAlias but not working
    – MD78692
    Oct 8, 2020 at 11:45

2 Answers 2

0

If you want to use a catch all, you configure a _default that is used for any of your subdomains, if you have one certificate that covers both domains through a SAN subject alternative name or a wildcard certificate this will work.

<VirtualHost _default_:443>

But if you have two separate certificates, you need two configuration VirtualHost blocks, they can be in the same file

<VirtualHost mywebsite.domain.com:443>
   <bla></bla>
</VirtualHost>
<VirtualHost mywebsite1.domain.com:443>
   <bla></bla>
</VirtualHost>
4
  • Thanks for your time, i have checked my certificate is wildcard certificate and also tried your way you suggested but it doesn't worked.
    – MD78692
    Oct 8, 2020 at 10:57
  • check the error log file for clues why it doesn't work. tail -50 /var/log/apache2/error.log
    – sleepyhead
    Oct 8, 2020 at 11:27
  • Yes it shows "server certificate does NOT include an ID which matches the server name"
    – MD78692
    Oct 8, 2020 at 11:33
  • I have added ip address in server name so now i have changed it to domain.com but now error gone but still it doesn't work
    – MD78692
    Oct 8, 2020 at 11:40
0

If you want to use a catch all, you configure a _default that is used for any of your subdomains, if you have one certificate that covers both domains through a SAN subject alternative name or a wildcard certificate this will work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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