0

Is it possible for me to have two virtual hosts (ports: 80 & 443) in one config file? i.e.

/etc/apache2/sites-available/example.test.conf

<VirtualHost *:443>
    ServerName example.test
    DocumentRoot /var/www/example.test/public
    SSLEngine on
    SSLCertificateFile /etc/apache2/ssl/example.test.crt
    SSLCertificateKeyFile /etc/apache2/ssl/example.test.key
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin admin@example.test
    ServerName example.test
    ServerAlias www.example.test
    DocumentRoot /var/www/example.test/public

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

I ran sudo a2ensite example.test.conf and restarted Apache.

Upon trying the above (https://example.test) setup, I receive:

enter image description here

In the browser. So, not the actual site contents? It's fine when served over http

4
  • Have you enabled the sites? At the moment they're in /sites-available/ and there's no indication you've used a2ensite to enable them
    – roaima
    Apr 25 at 14:19
  • Yes, I ran sudo a2ensite example.test.conf
    – cookie
    Apr 25 at 14:42
  • And restarted Apache?
    – roaima
    Apr 25 at 14:47
  • yes, I restarted Apache
    – cookie
    Apr 25 at 14:51

2 Answers 2

0

Is it possible for me to have two virtual hosts (ports: 80 & 443) in one config file?

Yes.

However, with regard to your testing, there isn't an https://example.text virtual host defined in the configuration you've shown us. What you do have is:

1
  • Yes, that was a copy/paste mistake, thanks
    – cookie
    Apr 26 at 8:21
0

Yes, it is. See: https://www.digitalocean.com/community/tutorials/how-to-create-a-self-signed-ssl-certificate-for-apache-in-ubuntu-20-04 for a full tutorial.

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.