Apache 2 vhost config
This is an example for Apache server vhost configuration.
It demonstrates the following:
- Redirection to the HTTPs version.
- Set custom error and access logs.
- Set IP restrictions.
- Set the path to the SSL keys.
- Disable the directory listing.
<VirtualHost *:80>
DocumentRoot /var/www/example.com/public
ServerName example.com
ServerAlias example.com
RedirectMatch ^(.*)$ https://example.com$1
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
LogLevel warn
CustomLog /var/log/apache2/example.com_access.log combined
ErrorLog /var/log/apache2/example.com_error.log
</VirtualHost>
<VirtualHost *:443>
ServerName example.com
DocumentRoot "/var/www/example.com/public"
<Directory "/var/www/example.com/public">
AllowOverride All
Options -Indexes
Order Allow,Deny
Allow from 83.222.184.82
Allow from 127.0.0.0/8
</Directory>
SSLEngine on
SSLCertificateFile /etc/ssl/example.com/example.com.crt
SSLCertificateKeyFile /etc/ssl/example.com/example.com.key
CustomLog "/var/log/apache2/example.com_access.log" combined
ErrorLog "/var/log/apache2/example.com_error.log"
</VirtualHost>