Configurare un namebased Vhost per Apache

Con la migrazione del mio dominio sul nuovo VPS, ora posso sbizzarrirmi con le configurazioni custom su Apache e quanto altro.

Come promemoria ecco un esempio di un Vhost Apache che risponde sia in 80 che in 443 namebased, cioè basato sull’Url chiamato da browser:

<VirtualHost *:80>
DocumentRoot “/var/www/html/wordpress/”
ServerAlias example.org
ServerName www.example.org
RewriteEngine on
RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R=301,L]
<Directory  “/var/www/html/wordpress/”>
Order allow,deny
Allow from all
Require all granted
Satisfy Any
</Directory>
</VirtualHost>

<IfModule mod_ssl.c>
<VirtualHost *:443>
DocumentRoot “/var/www/html/wordpress/”
ServerAlias example.org
ServerName www.example.org
<Directory  “/var/www/html/wordpress/”>
Order allow,deny
Allow from all
Require all granted
Satisfy Any
</Directory>
CustomLog /var/log/httpd/example-access.log combined
ErrorLog /var/log/httpd/example-error.log
SSLCertificateFile /etc/letsencrypt/live/example.org/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.org/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateChainFile /etc/letsencrypt/live/example.org/chain.pem
</VirtualHost>
</IfModule>