https for local env on Ubuntu 20.04 using apache2
Additional to: kifarunix.com /
Create Locally Trusted SSL Certificates with mkcert on Ubuntu 20.04
Setup with the DocumentRoot on a separate SSD Partition called Server # /media/user_many/Server/www
; OS drive
/Filesystem
/home
/user_many
/ssl-certs
; second drive: /media/user_many/Server
/Server
/www
/example.loc
/publiceg: /media/user_many/Server/www/example.loc/public
cd /media/user_many/Server/www
mkdir example.loc
cd example.loc
mkdir public
cd public
echo '<h1>Hakuna Matata!</h1>' > index.htmlsudo nano /etc/hosts
# add
127.0.0.1 example.loc www.example.loc# copy 'default.conf' for the new host
cd /etc/apache2/sites-available/
sudo cp 000-default.conf example.loc.conf
sudo nano example.loc.confset Defines (variables), copy all & paste to example.loc.conf
Define DEFAULT_HOSTNAME "example.loc"
Define DEFAULT_WWW_HOSTNAME "www.example.loc"
Define DEFAULT_CERT_ROOT "/home/user_many"
Define DEFAULT_DOC_ROOT "/media/user_many/Server/www/${DEFAULT_HOSTNAME}/public"
Define DEFAULT_CERT_APPIX "+1"
<VirtualHost *:80>
ServerName ${DEFAULT_WWW_HOSTNAME}
ServerAlias ${DEFAULT_HOSTNAME}
DocumentRoot ${DEFAULT_DOC_ROOT}
</VirtualHost>
<VirtualHost *:443>
ServerName ${DEFAULT_WWW_HOSTNAME}
ServerAlias ${DEFAULT_HOSTNAME}
SSLEngine On
SSLCertificateFile ${DEFAULT_CERT_ROOT}/${DEFAULT_HOSTNAME}${DEFAULT_CERT_APPIX}.pem
SSLCertificateKeyFile ${DEFAULT_CERT_ROOT}/${DEFAULT_HOSTNAME}${DEFAULT_CERT_APPIX}-key.pem
DocumentRoot ${DEFAULT_DOC_ROOT}
</VirtualHost>cd /home/user_many/ssl-certs
mkcert example.loc '*.example.loc' localhost 127.0.0.1 ::1<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
# Header set X-Frame-Options "allow-from https://www.google.com/"
# https extras
Header set Referrer-Policy "same-origin"
Header set Feature-Policy "geolocation 'self'"
Header set Content-Security-Policy "frame-ancestors 'self'"
Header set Strict-Transport-Security "max-age=31536000; includeSubDomains" env=HTTPS
Header always set Strict-Transport-Security "max-age=31536000" early
Header unset Strict-Transport-Security env=!HTTPS
Header set X-XSS-Protection "1; mode=block" "expr=%{CONTENT_TYPE} =~ m#text/html#i"
Header set X-Content-Type-Options "nosniff"
Header set X-Frame-Options "SAMEORIGIN"
</IfModule>
<IfModule mod_setenvif.c>
# SetEnvIf Authorization .+ HTTP_AUTHORIZATION=$0
<IfModule mod_headers.c>
<FilesMatch "\.(bmp|cur|gif|ico|jpe?g|png|svgz?|webp)$">
SetEnvIf Origin ":" IS_CORS
Header set Access-Control-Allow-Origin "*" env=IS_CORS
</FilesMatch>
</IfModule>
</IfModule># enable page
sudo a2ensite example.loc.conf
# restart server
sudo systemctl restart apache2
# have fun// always needed and always forgotten
_italic_ **bold** `monospace` ~~strikethrough~~