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 [email protected]
    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 Commented Apr 25, 2022 at 14:19
  • Yes, I ran sudo a2ensite example.test.conf Commented Apr 25, 2022 at 14:42
  • And restarted Apache? Commented Apr 25, 2022 at 14:47
  • yes, I restarted Apache Commented Apr 25, 2022 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 Commented Apr 26, 2022 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.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.