Create Virtual host on EC2 (ubuntu)

Steps

  1. sudo mkdir -p /var/www/rex.com/
  2. sudo chown -R ubuntu:www-data /var/www/rex.com/
  3. sudo chmod -R 755 /var/www/
  4. cd /etc/apache2/sites-available/
    sudo cp 000-default.conf rex.com.conf
    sudo nano rex.com.conf
  5. sudo a2ensite rex.com.conf
  6. sudo service apache2 restart
<VirtualHost *:80>
        ServerName lab.com
        ServerAlias www.lab.com
        ServerAdmin [email protected]
        DocumentRoot "/var/www/lab"
        <Directory />
                AllowOverride none
                Require all denied
        </Directory>
        <Directory "/var/www/lab">
                Options Indexes FollowSymLinks
                AllowOverride all
                Require all granted
        </Directory>
        ErrorLog ${APACHE_LOG_DIR}/lab-error.log
        CustomLog ${APACHE_LOG_DIR}/lab-access.log combined

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

Reference:

  1. http://diary.taskinghouse.com/posts/664386
  2. https://nouveauframework.org/blog/vhosts-running-multiple-sites-on-a-single-aws-ec2-instance/