2

I'm trying to setup a sub domain on my Ubuntu 17.10 machine. I got the HTTPS part working and that shows the right subdomain files, but when I put it as HTTP, it shows the main domain, but I want the HTTP to redirect and show the HTTPS version of the subdomain.

sites-available file:

<VirtualHost *:80>  
    ServerName forum.domain.com

    RewriteEngine on
    RewriteCond %{SERVER_NAME} =forum.domain.com
    RewriteRule ^ https://forum.domain.com%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

<IfModule mod_ssl.c>
<VirtualHost *:443>
    ServerName forum.domain.com
    DocumentRoot /var/www/forum/html

    <Directory /var/www/forum/html>
        AllowOverride All
    </Directory>
</VirtualHost>
</IfModule>

For some reason the HTTP version is just showing the main port 80 version of the website. I'm using Let's Encrypt for the HTTPS SSL encryption of the website (because it's free) and I've looked over the other conf files to not see any other errors myself

/etc/hosts file:

127.0.0.1   localhost
--.--.--.-- vps141---.vps.ovh.ca    vps141---
127.0.1.1   vps141---.vps.ovh.ca    vps141---
--.--.--.-- forum.domain.com

I had to take out some numbers so that I don't display my information to everyone viewing sorry :(

vidarlo
  • 23,497
Bwookzy
  • 89

1 Answers1

3

That's not a correct Vhost for SSL.

You have to actually turn on SSL on the VHost (SSLEngine on), specify a certificate and so on. Here is a reasonable starting point.

<VirtualHost *:443>
   DocumentRoot /var/www/forum/html/
   ErrorLog "logs/error_log"
   CustomLog "logs/access_log" common
   ServerName forum.domain.com
   ServerAlias www.forum.domain.com
   SSLEngine on
   SSLProtocol all -SSLv3 -SSLv2
   SSLCipherSuite HIGH:!aNULL
   SSLCertificateFile /etc/letsencrypt/live/forum.domain.com/cert.pem
   SSLCertificateKeyFile /etc/letsencrypt/live/forum.domain.com/privkey.pem
   SSLCertificateChainFile /etc/letsencrypt/live/forum.domain.com/chain.pem
   CustomLog /var/log/apache2/ssllog %t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
</VirtualHost>

To achieve a redirect, you can use the following for your regular vhost:

<VirtualHost *:80>
        ServerName forum.domain.com
        Redirect permanent / https://forum.domain.com/
</VirtualHost>
vidarlo
  • 23,497